Technical skill

Linux command: kill

Subject: .../LINUX

Ask a running program to stop

When an application freezes or a command keeps running, you may need to ask it to stop. Linux processes receive signals: short requests from the operating system or another program. The kill command sends a signal to a process or process group. Its name can be misleading. Without an explicit signal, the usual default is SIGTERM, a request that gives the program a chance to close files and clean up before exiting. A program may catch, block, or ignore it, so sending the request does not prove that the process ended.

Before sending a signal, check that the PID still belongs to the program you intend to stop. PIDs can be reused after a process exits, so a number copied from an old log may now refer to another program. Replace 1234 in this command with the PID you just checked:

kill -TERM 1234

Check the process again with ps or pgrep. If you started it from the current shell, Bash's builtin kill also accepts a job specification such as %1. For other processes, a verified PID is usually easier to interpret.

What stronger signals do

SIGKILL has a different effect. The kernel ends the process without giving it a chance to handle the signal, so application cleanup cannot run. Use it only after a reasonable graceful request has failed and you understand what interrupted work may leave behind. Even SIGKILL may not make a process disappear right away if it is stuck in uninterruptible kernel sleep; the signal remains pending until the task can be scheduled to handle it.

kill -l lists signal names supported by the local shell or utility. kill -0 PID checks permission and whether a process exists without sending it a signal. Success does not show that the program responds to requests or that its service is healthy. If the check fails, distinguish a missing process from a permission problem before changing the command.

Signals can have meanings chosen by each application. Some daemons document SIGHUP as a request to reload configuration or reopen log files; other programs may use its default action. Read the program's documentation before sending one. Negative PID forms target a process group, which can include several processes, so verify the group before using them.

Work with the service manager

For a systemd-managed service, use the unit's stop or reload operation. The manager knows the service lifecycle and can report whether it reached the requested state. Other systems have different service managers. If an unmanaged process remains after SIGTERM, inspect its current state and application logs, if available, before choosing another signal.

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 Skyeng Senior Backend Developer preview
image descriptionSkyeng Senior Backend Developer
by Artem Naumenko (slack2)
39 users
Skillset Skyeng QA Automation Hard Skillset v09.21 preview
image descriptionSkyeng QA Automation Hard Skillset v09.21
by Aleksandra Kulikova
16 users
Skillset Skyeng SRE preview
image descriptionSkyeng SRE
by Yuliya Marochkina
12 users
Show more
Do you know that ...?
Any useful or interesting facts about the skill. Any peace of information would be useful