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:
Syntax
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
#!/bin/bash
sleep 30 &
pid=$!
echo "Started process $pid"
kill "$pid"
echo "Sent termination signal to $pid"
Login to try C/C++/Java/PHP code in the editor
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
- Using
kill -9first, which prevents the process from cleaning up; try plainkillfirst. - Killing the wrong PID from an outdated value.
- Forgetting that
killonly 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: