counterintuitively, you can use
kill to send *any* signal,
not just signals which kill the process. For example:
$ kill -STOP 1234
will send a
SIGSTOP signal to PID 1234. The system call that's used to send signals is also called
to send a signal, you need to be running as the same user (or root). Otherwise, you'd be able to kill processes run by root, which would be bad!
kill PIDon it?
kill without any argument sends the
signal. The default behavior for processes when they get a
SIGTERM is to exit immediately.
any process can set signal handlers functions for a given signal (like
SIGINT). You can either use a predefined signal disposition (like
SIG_IGN for "ignore") or run a custom function.
Ctrl+Cin a terminal terminate the foreground process?
when you press
Ctrl+C in your terminal, the kernel
translates that into sending a
SIGINT signal to the
kill -9 PID, is it possible for the process to choose to handle it another way than just exiting immediately?
kill -9 sends the
SIGKILL signal, which can't
be blocked. It's a good way to force a process to exit immediately.
SIGSTOP can't be blocked either.
kill -9guaranteed to always kill a process?
processes can't block being killed with
SIGKILL by setting
a signal handler, but sometimes on Linux they get stuck doing I/O or something and become
impossible to kill. This unkillable state is called "uninterruptable sleep".
by default, signals don't wait for anything -- they just interrupt the process at a completely arbitrary point in its execution.
If you'd rather be interrupted only when it's convenient for the
process, you can set the process's signal mask to block signals and
sigwait when you want to receive them
kill PIDsend the same signal as pressing
Ctrl+Cin a terminal?
kill PID sends a
Ctrl+C sends a
SIGSTOP) cause the process to exit?
stopping the process is like hitting "pause" -- it stops using the CPU but all of the process's current state stays intact. You can resume it later and it'll pick up right where it left off.
if you have a program (like
vim) running in a terminal, you can send
SIGTSTP (which will also stop the process by default) to it by pressing
terminate the process by default, but processes sometimes use these
signals to reload configuration or print out debug info. For example,
if you send nginx a
SIGHUP, it'll reload its