Technical skill

Linux signals: send signal

Ask a running program to act

A process is a program that is running. Sometimes you need to ask it to stop or tell it that something happened. Linux uses signals for these short notifications. A signal can ask a program to exit, pause it, or report an event. The kill command sends a signal; despite its name, sending one does not always end a process.

For example, if ps shows that the program you want to stop has PID 1234, run kill -TERM 1234. Here, TERM is a request to stop politely. Then check ps or the service's status to see whether it has actually exited. Replace 1234 with the current PID; process IDs can be reused after a program ends.

Choose a signal for the job

SIGTERM is the default signal sent by kill. It gives a program a chance to finish work and clean up. The program can handle the request, temporarily block it, or ignore it, so the request may not finish immediately. SIGKILL forces the kernel to terminate a process; a program cannot catch, block, or ignore it, so it cannot perform its own cleanup. Use it only after a graceful stop fails and you know it is safe to skip cleanup.

SIGSTOP pauses a process and cannot be caught, blocked, or ignored. SIGCONT resumes a stopped process. At an interactive terminal, Ctrl-C normally sends SIGINT to the foreground process group, a set of related processes. If you started a pipeline, several processes in that group may receive it. A name such as SIGTERM is clearer and more portable than a numeric signal value.

Some signals have application-specific uses. A daemon may treat SIGHUP as a request to reload configuration or reopen log files, but another program may exit or act differently. Read the program's documentation before using it for a reload.

Check permission and the result

Use ps to confirm a process's PID, owner, and command before sending a signal. The process may exit between the check and the request. A successful kill command means the kernel accepted the request; it does not prove that shutdown has finished. Check the process or service state afterward.

On Linux, the sender normally needs a matching user ID or the CAP_KILL permission in the target's user namespace, the scope that defines its user IDs. A missing PID and a permission error point to different problems. On common Linux implementations, kill -l lists signal names. kill -0 PID sends no signal; it checks whether the process exists and whether you may signal it. It does not show whether the process is healthy or able to handle requests.

At the underlying Linux kill interface, a negative process ID can address a process group. Confirm the group ID and its members before signaling a group. When a process belongs to a managed service, use the service manager's stop or reload operation and check its reported state. The manager knows the unit configuration and may track several related processes.

Interactive exercises

Materials

Skillsets
Skillset Linux for backend developer preview
image descriptionLinux for backend developer
by Artem Naumenko (fb)
16 users
Skillset Linux administrator preview
image descriptionLinux administrator
by Infinite Education
3080 users
Skillset Devops preview
image descriptionDevops
by Ajay Kumar
2004 users
Skillset Devops preview
image descriptionDevops
by Dio
3 users
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful