← Back to Bash Course | Chapter 10: Text Processing Tools | Lesson 6 of 12

kill

kill is like tapping a runner on the shoulder to ask them to stop nicely. If they will not listen, the stronger version yanks them off the track right away.

In this page:

  1. kill
Syntax
bash
kill [-signal] process_id

kill

kill sends a signal to a process, most commonly SIGTERM (the default) to ask it to terminate gracefully, or SIGKILL (kill -9) to force it to stop immediately.

You target a process by its PID. Scripts use kill to stop background jobs they started, such as a server process spun up for testing.

Warning: kill -9 (SIGKILL) cannot be caught or ignored by the process, so it never gets a chance to clean up before exiting.

Example: kill

bash
#!/bin/bash
sleep 30 &
pid=$!
echo "Started process $pid"

kill "$pid"
echo "Sent termination signal to $pid"
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
Common Mistakes
  1. Using kill -9 first, which prevents the process from cleaning up; try plain kill first.
  2. Killing the wrong PID from an outdated value.
  3. Forgetting that kill only sends a signal, which the process may handle or ignore.
🔒

Chapter Quiz — Complete all 12 topics to unlock

0/12 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.