You can stop processes with the kill command.

Sometimes you may see a process running that you don’t want running anymore. The process may be an unwanted one that wasn’t properly killed previously. Or maybe it’s a process you put into the background and then reconsidered. Sometimes X programs don’t give you an obvious way to exit. For example, the xclock program doesn’t allow you to exit cleanly.

When you do have a way to exit a program cleanly, it’s always better to stop the program that way instead. This is because programs usually have a cleanup procedure that they perform before exiting, and you want them to be able to complete it. For example, when you quit out of vi, it warns you if the file hasn’t been written since the last change, and it removes its temporary files in /tmp. If you kill vi externally, the latest changes are lost, and the temporary files remain on the system.

To kill a process, you can use the kill command. The one inconvenient thing about kill is that you need to tell it which process to kill, and usually the only way to do that is to use the process number. So you have to first use the ps command to get the process number. For example, suppose we want to kill the more ch01 process shown below:

% ps
  PID TT STAT  TIME COMMAND
13745 q7 I     0:02 -csh (tcsh)
24912 q7 T     0:00 more ch01
26355 q7 R     0:00 ps

The process number is shown in the PID column (process ID). To kill the process, supply this number to the kill command:

% kill 24912

Then run ps again to make sure that ...

Get WYNTK: UNIX System Admininistrator now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.