Name
kill — stdin stdout - file -- opt --help --version
Synopsis
kill [options
] [process_ids
]
The kill
command sends a
signal to a process, given its process ID (PID). This can terminate a
process (the default action), interrupt it, suspend it, crash it, and
so on. You must own the process, or be the superuser, to affect it.
Remember our story in the introduction about terminating a hung
Microsoft Word? We used a kill command (actually killall
, described shortly) for this
purpose, since it can succeed when other more common methods have
failed.
To terminate the process with PID 13243, for example, run:
➜ kill 13243
You can also terminate a shell job (see Shell Job Control) by its job number, preceded by a percent sign to distinguish it from a PID:
➜ kill %2
If kill
does not work—some
programs catch this signal without terminating—add the option -KILL
or (equivalently) -9
:
➜ kill -KILL 13243
which is virtually guaranteed to work. However, this is not a clean exit for the program, which may leave system resources allocated (or cause other inconsistencies) upon its death.
If you don’t know the PID of a process, run ps
and examine the output:
➜ ps -ax | grep emacs
or even better, try the killall
command, which looks up all
processes for a given program by its name and kills them:
➜ killall less
[1]+ Terminated: 15 less -c myfile
In addition to the kill
program in the filesystem (usually /bin/kill), most shells have built-in
kill
commands, but their syntax and behavior differ. However, they all ...
Get Macintosh Terminal Pocket Guide 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.