kill Command in Linux

Learn via video courses
Topics Covered

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Overview

The 'kill' command in Linux is a powerful tool that you, as a system administrator, can utilize to manage processes effectively. The main purpose of the 'kill' command in Linux is to send a signal to a process, primarily to stop the process. It is important to note that 'kill' doesn't necessarily mean to terminate the process. Depending upon the signal sent, the process may continue running, stop, or even ignore the signal altogether.

Syntax of kill Command in Linux

The basic syntax of the kill command in Linux is as follows:

Where:

  • options: These are optional and modify the behavior of the kill command.
  • signal: This specifies the type of signal to be sent to the process.
  • PID: This is the Process ID to which the signal will be sent.
Free Courses by top Scaler instructors
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course
Python Course for Beginners With Certification: Mastering the Essentials
Java Course - Mastering the Fundamentals
DBMS Course - Master the Fundamentals and Advanced Concepts
JavaScript Course With Certification: Unlocking the Power of JavaScript
C++ Course: Learn the Essentials
Python and SQL for Data Science Course

Options in kill Command in Linux

  1. -l, --list=[signal]: List all signal names, or convert a signal number to a name.

    For example -

    Output:

    This command converts the signal number 9 to its corresponding name, which is 'KILL'.

  2. -s, --signal=[signal]: Specify the signal to be sent.

    For example -

    Output:

    This command sends the HUP (hangup) signal to the process with PID 1234.

  3. -p, --pid: Only print the process ID (PID) to the terminal.

    For example -

    Output:

    This command prints the PID 1234 without sending any signals.

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data
Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more

Example Usages

  • Sending a SIGSTOP signal to a process.:

    Output:

    Explanation: This command sends a STOP signal to the process with PID 1234, effectively pausing it.

  • Sending a SIGCONT signal to a paused process.:

    Output:

    Explanation: This command sends a CONT signal to the paused process with PID 1234, causing it to resume its execution.

Tips

  • Before using 'kill' to terminate a process, it is recommended to try sending the SIGTERM (-15) signal first, which asks the process to terminate gracefully.

  • If a process doesn't respond to a SIGTERM signal, you may then use the SIGKILL (-9) signal, which forces the process to terminate immediately.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

Advanced Use Cases of kill Command in Linux

  • Killing all processes of a particular name.:

    Output:

    Explanation: This command kills all running instances of 'processname' by sending them the SIGKILL (-9) signal.

  • Killing all processes of a particular user.:

    Output:

    Explanation: This command kills all running processes owned by 'username'.

  • Using the 'kill' command with 'ps' and 'grep' to kill a process.:

    Output:

    Explanation: This command first finds the PID of 'processname' using 'ps', 'grep', and 'awk', and then kills it.

Conclusion

  • 'kill' in Linux is a powerful command to manage processes.

  • Different signals can be sent to a process, affecting its execution in different ways.

  • Always try sending a SIGTERM before a SIGKILL to allow a process to terminate gracefully.