Removing a background process (kill command)
If INTERRUPT does not halt your foreground process or if you decide, after starting a background process, that you do not want the process to finish, you can cancel the process with the kill command.
Before you can cancel a process using the kill command,
you must know its PID number. The general format for the kill command
is as follows:
kill ProcessID
Note:
- To remove a process, you must have root user authority or be the user who started the process. The default signal to a process from the kill command is -15 (SIGTERM).
- To remove a zombie process, you must remove its parent process.
- Use the ps command to determine the process ID of the
process you want to remove. You might want to pipe this command through a grep command
to list only the process you want. For example, if you want the process ID
of a vi session, you could type the following:
ps -l | grep vi
- In the following example, you issue the find command
to run in the background. You then decide to cancel the process. Issue the ps command
to list the PID numbers.
$ find / -type f > dir.paths & [1] 21593 $ ps PID TTY TIME COMMAND 1627 pts3 0:00 ps 5461 pts3 0:00 ksh 17565 pts3 0:00 -ksh 21593 pts3 0:00 find / -type f $ kill 21593 $ ps PID TTY TIME COMMAND 1627 pts3 0:00 ps 5461 pts3 0:00 ksh 17565 pts3 0:00 -ksh [1] + Terminated 21593 find / -type f > dir.paths &
The command kill 21593 ends the background find process, and the second ps command returns no status information about PID 21593. The system does not display the termination message until you enter your next command, unless that command is cd.
The kill command lets you cancel background processes. You might want to do this if you realize that you have mistakenly put a process in the background or that a process is taking too long to run.
See the kill command in the Commands Reference, Volume 3 for the complete syntax.
The kill command can also used in smit by
typing:
smit kill