DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Modify Java Command-Line Arguments
  • JGit Library Examples in Java
  • Quickly Find Your Java Application Process ID
  • Step By Step Guide To Using Mule ESB

Trending

  • A Modern Stack for Building Scalable Systems
  • Comparing SaaS vs. PaaS for Kafka and Flink Data Streaming
  • Doris: Unifying SQL Dialects for a Seamless Data Query Ecosystem
  • How the Go Runtime Preempts Goroutines for Efficient Concurrency
  1. DZone
  2. Coding
  3. Java
  4. How to Kill Processes in Unix/Linux

How to Kill Processes in Unix/Linux

How to decide which kill command to use to best terminate a process

By 
Ram Lakshmanan user avatar
Ram Lakshmanan
DZone Core CORE ·
Jan. 12, 21 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
45.0K Views

Join the DZone community and get the full member experience.

Join For Free

There are different options to terminate a process in Unix/Linux flavor of operating systems. This article intends to list and provide examples of each option.

kill

You can use the kill command to terminate a process by passing the process id. PID is the process ID of the process that you want to terminate. 

Java
 




x


 
1
kill {PID}



If you want to kill a process whose PID is 1692 then the command would be:

Java
 




xxxxxxxxxx
1


 
1
kill 1692



Sometimes when you issue the kill command you may get an ‘operation not permitted’ error message. In those circumstances, issue the kill command with a ‘-9’ signal.

Java
 




xxxxxxxxxx
1


 
1
kill -9 {PID}
2
kill -9 1692



If you continue to get an ‘operation not permitted’ error message even with the ‘kill -9’ signal then you may not have sufficient permission to terminate the process. Then you need to ‘sudo’ as a ‘root’ user (i.e. login as a superuser) and then issue the ‘kill -9’ command.

Note: This is the same as the ‘run as administrator’ option in Windows.
Terminating the process with ‘kill -9’ signal

Fig: Terminating the process with ‘kill -9’ signal

killall

killall command is another option to terminate multiple processes in one stroke. You can use this option to kill processes based on their names or by the users who launched them. Let’s explore all killall options in this section. 

  • killall process_name:  Kill processes that match the specified process name. For example, refer to line 2 if you want to kill the process whose process name is ‘java.'
Java
 




xxxxxxxxxx
1


 
1
killall {ProcessName}
2
killall java



killall processname

Fig: killall processname

Note: If 3 processes are running with the name ‘java’, then when you use killall, all 3 processes will be terminated.

  • killall -I process_name: Ignore case when trying to find the process name. If you want to kill the process whose process name is ‘java’,  but if you are not sure about the case sensitivity of the process, then you can use ‘-l’ option. Refer to the example on line 2.
Java
 




xxxxxxxxxx
1


 
1
killall -I {ProcessName}
2
killall -I JAVA



  • killall -i process_name:  Ask for additional confirmation when killing the process. If you want to kill the process whose process name is ‘java’ and the system requires confirmation, refer to the example on line 2.
Java
 




xxxxxxxxxx
1


 
1
killall -i {ProcessName}
2
killall -i java




Fig: Killall Confirmation

  • killall -u username: Kills processes owned by a specific user. Line 1 demonstrates this. If you want to kill all the processes owned by the username ‘ec2-dev’, refer to the example on line 2.
Java
 




xxxxxxxxxx
1


 
1
killall -u {UserName}
2
killall -u ec2-dev



  • killall -v process_name: Report back on whether the process has been successfully killed.
Java
 




xxxxxxxxxx
1


 
1
killall -v {ProcessName}
2
killall -v java



Process Killed ReportedFig: Process Killed Reported

pkill

You can use the pkill command to terminate processes by sending a full name or partial name of the process. By default, pkill will send the signal SIGTERM. If you want to kill the process whose process name is ‘java’,  refer to the example on line 2.

Java
 




xxxxxxxxxx
1


 
1
pkill {ProcessName}
2
pkill java



The Difference Between ‘killall’ and ‘pkill’

killall will look for the exact match of the process name whereas pkill will allow terminating the process either by full name or by partial process name.

Example: There is a process with the name ‘java’. If you try to terminate the process using ‘killall’ command by giving a partial name, i.e. ‘ava’, then you will get a ‘no process found’ error:

No process found error

Fig. killall using partial process name

On the other hand if you try to terminate the process using the pkill command by giving a partial name, i.e., ‘ava’, it will succeed:


successful partial process name

Fig. pkill using partial process name

top

You can also terminate a process using the popular system monitoring tool – top. Below are the steps to terminate a process in top:

  1. Press the ‘k’ key when the top command is running
  2. You will be prompted to enter the PID you want to terminate. Type the PID.
  3. You will be prompted to enter which signal you want to use to kill the process. Type '9' which is a SIGKILL. By default, the signal will be SIGTERM ('15').
  4. Press enter

    Killed the process which has the process_id 11524 using the signal SIGKILL 9

Fig: killed using SIGKILL signal


Command (computing) Java (programming language)

Opinions expressed by DZone contributors are their own.

Related

  • How to Modify Java Command-Line Arguments
  • JGit Library Examples in Java
  • Quickly Find Your Java Application Process ID
  • Step By Step Guide To Using Mule ESB

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!