www.tecmint.com
Open in
urlscan Pro
2606:4700:20::681a:317
Public Scan
Submitted URL: http://tecmint.com/how-to-kill-a-process-in-linux/
Effective URL: https://www.tecmint.com/how-to-kill-a-process-in-linux/
Submission: On September 26 via api from QA — Scanned from DE
Effective URL: https://www.tecmint.com/how-to-kill-a-process-in-linux/
Submission: On September 26 via api from QA — Scanned from DE
Form analysis
3 forms found in the DOMPOST https://www.tecmint.com/wp-comments-post.php
<form action="https://www.tecmint.com/wp-comments-post.php" method="post" id="commentform" class="comment-form" novalidate="">
<div class="article_comments_notice">
<p>Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our
<a href="https://www.tecmint.com/comment-policy/" target="_blank">comment policy</a> to ensure a respectful and constructive conversation.</p>
<p>Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.</p>
</div>
<p class="comment-form-comment"><label for="comment" class="screen-reader-text">Comment</label><textarea id="comment" name="comment" cols="45" rows="8" required=""></textarea></p><label for="author" class="screen-reader-text">Name</label><input
placeholder="Name *" id="author" name="author" type="text" value="" size="30" required="">
<label for="email" class="screen-reader-text">Email</label><input placeholder="Email *" id="email" name="email" type="email" value="" size="30" required="">
<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"> <label for="wp-comment-cookies-consent">Save my name, email, and website in this browser for the next time
I comment.</label></p>
<p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment"> <input type="hidden" name="comment_post_ID" value="4182" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
</p>
<p style="display: none;"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="86c7a44f3e"></p>
<p style="display: none !important;" class="akismet-fields-container" data-prefix="ak_"><label>Δ<textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label><input type="hidden" id="ak_js_1" name="ak_js"
value="1727329512599">
<script>
document.getElementById("ak_js_1").setAttribute("value", (new Date()).getTime());
</script>
</p>
</form>
GET https://www.google.com/cse
<form method="GET" class="search-form" action="https://www.google.com/cse" target="_blank">
<div class="search-form-inner"> <input name="cx" type="hidden" value="76796a99e56f9430c"> <input name="ie" type="hidden" value="UTF-8"> <input class="tecmintsearchbox" type="search" placeholder="Search..." name="q" style="width: 100%;" required="">
</div>
</form>
GET https://www.tecmint.com/
<form role="search" method="get" class="search-modal-form" action="https://www.tecmint.com/">
<label class="screen-reader-text">Search for:</label>
<div class="search-modal-fields">
<input type="search" class="search-field" placeholder="Search …" value="" name="s">
<button aria-label="Search"><span class="gp-icon icon-search"><svg viewBox="0 0 512 512" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="1em" height="1em">
<path fill-rule="evenodd" clip-rule="evenodd"
d="M208 48c-88.366 0-160 71.634-160 160s71.634 160 160 160 160-71.634 160-160S296.366 48 208 48zM0 208C0 93.125 93.125 0 208 0s208 93.125 208 208c0 48.741-16.765 93.566-44.843 129.024l133.826 134.018c9.366 9.379 9.355 24.575-.025 33.941-9.379 9.366-24.575 9.355-33.941-.025L337.238 370.987C301.747 399.167 256.839 416 208 416 93.125 416 0 322.875 0 208z">
</path>
</svg></span></button>
</div>
</form>
Text Content
Skip to content Unlocking Clouds: An Easy Guide to LFCS Certification eBook Menu Menu * Learn Linux * Linux Distros * Linux Distros for Beginners * Linux Distros for Experts * New Linux Distros * Linux Server Distros * Secure Linux Distros * CentOS Alternatives * RedHat Distributions * Debian Distributions * Ubuntu Distributions * Arch Linux Distros * Rolling Linux Distros * KDE Linux Distros * Linux Distros for Old PC * Linux Distros for Kids * Linux Distributions for Students * Linux Distros for Windows * Commands * A – Z Linux Commands * 100+ Linux Commands * Tools * Tutorials * Docker Tutorials * Ansible Tutorials * Postfix Tutorials * Django Tutorials * LVM Tutorials * RAID Tutorials * KVM Tutorials * iSCSI Tutorials * Red Hat Virtualization * Hadoop Tutorials * Zentyal Tutorials * Create GUI Apps * eBooks * RHCSA Exam * RHCE Exam * LFCS Exam * LFCE Exam * LFCA Exam * Ansible Exam * About * Contact * Hiring * Newsletter * Testimonials * Donate * Advertise * Submit Article Request * Suggest an Update Menu * Learn Linux * Linux Distros * Linux Distros for Beginners * Linux Distros for Experts * New Linux Distros * Linux Server Distros * Secure Linux Distros * CentOS Alternatives * RedHat Distributions * Debian Distributions * Ubuntu Distributions * Arch Linux Distros * Rolling Linux Distros * KDE Linux Distros * Linux Distros for Old PC * Linux Distros for Kids * Linux Distributions for Students * Linux Distros for Windows * Commands * A – Z Linux Commands * 100+ Linux Commands * Tools * Tutorials * Docker Tutorials * Ansible Tutorials * Postfix Tutorials * Django Tutorials * LVM Tutorials * RAID Tutorials * KVM Tutorials * iSCSI Tutorials * Red Hat Virtualization * Hadoop Tutorials * Zentyal Tutorials * Create GUI Apps * eBooks * RHCSA Exam * RHCE Exam * LFCS Exam * LFCE Exam * LFCA Exam * Ansible Exam * About * Contact * Hiring * Newsletter * Testimonials * Donate * Advertise * Submit Article Request * Suggest an Update HOW TO KILL A PROCESS IN LINUX FROM COMMAND LINE Ravi SaiveLast Updated: December 14, 2023 Read Time: 5 minsCategories Linux Commands 40 Comments In Linux, killing a process refers to terminating or stopping the execution of a running program. Each running process is assigned a unique identifier number known as the Process ID (PID), which helps the system to keep track of currently active processes. In this article, we’ll find out about the Linux kill process and how to find and terminate a process using different tools and commands in Linux. WHAT IS THE LINUX PROCESS In simple terms, a process is like a program that’s currently running on a system, and each process has its own special ID (PID) number. However, sometimes a running program, or process, can misbehave or might stop responding or use up too much of the system resources. When that happens, we need to stop or “kill” the process and this is where the kill command comes in handy. WHAT IS KILL COMMAND The “kill” command is a crucial utility that allows users to send signals (stop or terminate) to currently running processes, instructing them to gracefully exit or forcefully terminate. The kill command is useful when you need to manage and control the activities of different programs on your Linux system such as: * To stop any automated process. * To stop a process that has been started by accident. * To stop a process that uses too much memory. * To forcefully terminate any running process in Linux. * To stop a process running in the background. Using the kill command from /usr/bin provides you with some extra features to kill a process by process name using pkill, which identifies processes by their names. HOW TO FIND PROCESS ID OR PROCESS NAME Before terminating a running process, it’s essential to identify its Process ID (PID) or name using the following ps command that displays information about all running processes on the system with their PID (process ID) and other information. $ ps -ef List All Running Processes If you want to find a specific process name PID, you can use a grep command that will list all processes running on the system and filter the results to show only those containing the term “mariadb“. ps -ef | grep mariadb Alternatively, you can directly find the PID of a process by name using the pgrep command as shown. pgrep mariadb Find Process PID HOW TO KILL A PROCESS IN LINUX Before you kill, stop, or terminate a process, think about permissions. If you’re a root user, you can stop any process, but if you are a normal user, you need to add a “sudo” before the command or switch to a root with “su” to use the termination command. The common syntax for the kill command is: kill [signal or option] PID(s) OR sudo kill [signal or option] PID(s) For a kill command a Signal Name could be: Kill Command Signals Clearly from the behavior above: * SIGTERM is the default and safest way to kill a process. * SIGHUP is a less secure way of killing a process than SIGTERM. * SIGKILL is the most unsafe way among the above three, to kill a process that terminates a process without saving. In Linux, there are different signals you can use to stop, end, or pause processes. You can list all available kill signals with their names and corresponding numbers using the following command, which will list kill -l While there are multiple available signals, but in most cases we only use SIGKILL (9) and SIGTERM (15). List Kill Command Signals To kill a process, we need to know the Process ID of a process. A Process is an instance of a program. Every time a program starts, automatically a unique PID is generated for that process. Every Process in Linux has a pid. The first process that starts when the Linux System is booted is the – init process, hence it is assigned a value of ‘1‘ in most cases. [ You might also like: Learn About Processes in Linux [Comprehensive Guide] ] Init is the master process and can not be killed this way, which ensures that the master process doesn’t get killed accidentally. Init decides and allows itself to be killed, where kill is merely a request for a shutdown. [ You might also like: How to Find Top Running Processes by Memory Usage ] Before we step ahead and execute a kill command, some important points to be noted: * A user can kill all his processes. * A user can not kill another user’s process. * A user can not kill processes the System is using. * A root user can kill the system-level process and the process of any user. To kill the mariadb process PID, use the kill command as shown. kill -9 3383 The above command will kill the process having pid=3383, where PID is a Numerical Value of the process. Another way to perform the same function can be rewritten as. kill -SIGTERM 3383 Similarly ‘kill -9 PID‘ is similar to ‘kill -SIGKILL PID‘ and vice-versa. To confirm that the process has terminated, you can again use the ps command. ps -ef | grep mariadb Kill Linux Process with PID HOW TO KILL MULTIPLE PROCESSES IN LINUX To terminate multiple processes in Linux using their Process IDs (PIDs), you can use the kill command in combination with the relevant PID numbers. First, identify the PIDs of the processes you want to terminate using the ps or pgrep command. ps aux | grep apache2 OR pgrep apache2 Once you have the PIDs, use the kill command to terminate them. kill -9 PID1 PID2 PID3 HOW TO KILL A PROCESS IN LINUX USING PROCESS NAME To terminate a process using the process name, we will use the pkill command, which is a version of the kill command that allows you to mention the process name or a pattern to locate a process. You must be aware of the process name, before killing, and entering a wrong process name may screw you. pkill mysqld What if a process has too many instances and several child processes, we have a command ‘killall‘ that takes the process name as an argument in place of the process number. HOW TO KILL A PROCESS IN LINUX USING THE KILLALL COMMAND The main distinction between killall and kill is that killall can end a process by its name, whereas the kill command relies on the process ID (pid). To kill all mysql instances along with child processes, use the command as follows. killall mysqld OR pkill mysqld You can always verify the status of the process if it is running or not, using any of the below commands. systemctl status mysql pgrep mysql ps -aux | grep mysql Linux graphical systems monitor tools like htop or gnome-system-monitor provide a user-friendly interface to find and kill processes. CONCLUSION That’s it for now from me. I’ll be back soon with another interesting and informative topic. Until then, stay tuned and connected to Tecmint, and take care of your health. Don’t forget to share your valuable feedback in the comments section. Hey TecMint readers, Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20! Learn more about the contest and stand a chance to win by sharing your thoughts below! Previous article: 3 Ways to Change a User Default Shell in Linux Next article: 12 Linux ‘df’ Commands to Check Disk Space Usage Ravi Saive I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies -------------------------------------------------------------------------------- Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards. Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed) Was this article helpful? Please add a comment or buy me a coffee to show your appreciation. RELATED POSTS How to Split Large ‘tar’ Archive into Multiple Files of Certain Size How to Transfer Files (Local and Remote) in Linux How to Sync New and Changed Files Using ‘rsync’ Command How to Search Files by Name or Extension Using find Command 10 Lesser Known Linux Commands – Part 2 11 Lesser Known Useful Linux Commands 40 COMMENTS Leave a Reply 1. James August 25, 2021 at 3:35 pm How do I kill a process that freezes everything so I can’t open a terminal? Reply 2. as May 2, 2019 at 11:03 am Kill isn’t for kill processes. Kill is for send signals to other processes. And no, there is no relationship between uptime and the kill/pkill/etc commands. Most software has a standard start/stop procedure, some of them use kill, but others not. Reply 3. Gordon June 27, 2018 at 11:01 am Thanks. It was a helpful information. Reply 4. Dave April 19, 2018 at 1:27 am Hey @oke deh, the output of your ‘ps‘ command is showing the ‘grep‘ command, not a process called ‘vnc‘. By the time you run the kill command, the grep has completed and so the process id no longer exists, so you can’t kill it. Everything you have shown above is working exactly as it is supposed to work, assuming there is no process running on the machine called ‘vnc*‘. You should try with just ‘vnc‘, as your grep command is the thing wrong here, not the kill command… Reply 5. oke deh January 1, 2018 at 12:12 am Hello tecmint, I try to kill this process but its not working… "[root@rms ~]# ps -afe|grep vnc* root 19784 19688 0 00:02 pts/0 00:00:00 grep vnc*" I tried following command.. # kill -9 19784 return this output "-bash: kill: (19784) - No such process" what is the correct command? Reply * raghu March 14, 2019 at 6:35 am just use kill 19784 Reply * Ismael April 30, 2019 at 1:34 am The kill PID you are using is for the grep issued, just do this to get the PID. # ps -afe|grep vn[c] That will return only PID for VNC and the just issue the kill PID Reply * Paruchuri Ravi Teja October 27, 2022 at 10:15 am I think it has a master and working process. Without killing the master you can’t kill the process. The same problem happens with nginx. Reply 6. Artur September 30, 2017 at 11:59 pm In order to `kill skypeforlinux` I have used `killall skypeforlinux` two times (because of a wingpanel I believe), but now actually I use this pidof skypeforlinux | xargs kill -9 and it kills my skypeforlinux in one go :) . A good article. Reply 7. vivek April 11, 2017 at 10:29 am I am using kill -9 $pid command to kill my server. However, sometimes if I restart the server, I get an exception as an address already in use that is the port is still in use (port number 6001) even after stopping the server using the above mentioned command. Is there any other safe command to use to kill my server so that the port is also freed along with killing of the process Reply * Vladimir May 25, 2017 at 8:11 pm You can find PID-s of all processes on a port with command *lsof -i :6001*, where 6001 is a number of your port. Then you can kill all processes on that port with *kill* command. Reply 8. Carsten January 30, 2017 at 1:13 pm Thank u for this article :) Reply 9. Afsar January 16, 2017 at 11:15 pm Very good article, I can learn now easily.. Reply 10. Mehmet Yesilçay December 9, 2016 at 5:46 pm thanks for sharing Reply 11. ymkim December 3, 2015 at 8:53 am Thank you very much. I was able to solve my problem, thanks to you. “KamSaHamNiDa!!!” Reply 12. Martial October 11, 2015 at 5:25 am Just to say thank you very much Avishek however I would like to know how the root can kill a specific process for an user, please can you give me with a scenario. Thanks again. Reply * Ravi Saive October 12, 2015 at 11:36 am @Martial, First find the all the processes and Process IDs of particular users by running following command. # ps -aux | grep {user} And then kill the specific process by their process ID’s Reply 13. Stig September 1, 2015 at 7:45 pm Thanks a lot! Great guide! Reply 14. Vijay March 20, 2015 at 8:59 am Very nice Reply 15. Don Porter February 23, 2015 at 9:53 pm Something is messed up. I’ve installed Varnish 3.0 via apt-get install running Raspbian on my Pi 2. For some reason, my “service” commands don’t work. ” sudo service varnish start” yields “varnish: unrecognized service”. Please advise how I can straighten this out. Thanks very much. Reply 16. rajas February 11, 2015 at 11:32 pm how to avoid to kill any process. I mean suppose I do not want anybody to kill mysql service using kill command so how can I do this? Awaiting your reply, Rjas Reply * Avishek Kumar February 12, 2015 at 3:40 pm @rajas, if the process was started with root privileged, it can not be killed by any user unless the user is sudoers. Reply 17. Cesar December 1, 2014 at 10:49 pm I have problems with chrome slowing down my system, so I’m used to kill all stances of chrome with this command: $ while [pidof chrome]; do killall chrome; done Reply * Avishek Kumar December 5, 2014 at 2:55 pm Dear Cesar, Thanks for the above quick tip. :) Keep connected! Reply 18. Sriram October 1, 2014 at 4:28 pm Hi, Can you please tell how to kill all the process running when i close the terminal/screen. Thanks. Reply * Avishek Kumar October 2, 2014 at 2:51 pm Dear sriram, i Didn’t get you question. When you close a terminal. All the running processes gets killed except those running in background and you can kill those by finding their pid. Reply 19. tamal2015 August 2, 2014 at 9:42 am hi…can u tell me the procedure to replace graphic card in red hat linux enterprise 6.0?…my pc was shipped with nvidia 610GT(zotac made GT610) but i need to replace it with nvidia 210GT(asus made En210). the second card is downgraded than the first one.Also can u inform me whether I need to do free OS install or not for this? ur kindness is appreciated on this!!! Reply * Avishek Kumar December 5, 2014 at 2:56 pm I fear it would be built on the board and perhaps u cant swap it. Ask your Vendor for such detailed hardware information. Reply 20. linux fresher September 27, 2013 at 8:59 am may god bless this website to me more powerful than RHKB. Please list out INterview section for new admins. Reply * Avishek Kumar January 2, 2014 at 2:52 pm @ Linux Fresher, I didn’t get you properly, although as far as i could understand, you said words for Appraisals for us. Thanks Reply 21. Sangeet Khatri September 20, 2013 at 8:45 pm Also xkill is the easiest way to kill a process using just your mouse. Just type ‘xkill’ in the terminal and then it would change the cursor to a cross, then just click on the process you want to kill and you are done. It is as easy as that. Please add this also. This is very useful in some really frustrating situations like stuck in the middle of a game, then just do Alt+Ctrl+T to bring up the terminal and kill the game using xkill. It has helped me quite a lot of times, it might help you also. Reply * Avishek Kumar December 5, 2014 at 2:59 pm Dear Sangeet Khatri, Thanks for the Quick tips. Keep Connected! Reply 22. ubungu September 20, 2013 at 4:36 pm Thank techmint for valuable posts :) Thank again for good tip :) Reply * Avishek Kumar December 5, 2014 at 2:59 pm Welcome ubungu. Keep connected! Enjoy Reply 23. akane September 20, 2013 at 1:32 am DO NOT use kill to stop services as a first resort. This will mess up your system if you do it regularly. Use the init scripts already set up for that purpose, or whichever program is provided for control of the service. Normally, for example to stop rsyncd, you should use “/etc/init.d/rsync stop”. You can use the same script to start, restart, or get status of the service. Read the script to learn more about what it does. If you have Upstart installed, then the “service” command works similarly (but arguably better). The syntax is “service rsync restart” to restart rsyncd, for example. Currently Upstart does not support all services in Debian-based distros, so you might need to use the previous method. Many services come with their own maintenance programs separate from the init.d scripts. For example, apache2 httpd comes with apachectl. Finally, while the “kill” command is mostly used to stop processes, it can send *any* signal. Check out the manpage for more information. kill is much more useful than explained here- but also more dangerous. Reply * Pawel September 20, 2013 at 1:15 pm Killall on Solaris will kill all processes on the system making it unusable. so it’s not a good habit to use killall. So use it with extreme care first check then use :-) Reply 24. siddiqullah September 19, 2013 at 11:27 pm i usually see interesting topics of linux in this site.i realy like this site ,because it gets me femiliar with linux and i have leant alot upto know. thanks Reply * Avishek Kumar December 5, 2014 at 2:58 pm Dear Siddiqullah, Thanks for your good words. Keep Connected. Enjoy! Reply 25. Suvarna September 19, 2013 at 2:42 pm Really very helpful information. I will try to use this to decrease server load. Thank You Tecmint for sharing all valuable posts. Reply * Avishek Kumar December 5, 2014 at 2:57 pm Welcome Suvarna, Keep Connected, Enjoy! Reply GOT SOMETHING TO SAY? JOIN THE DISCUSSION... CANCEL REPLY Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation. Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users. Comment Name Email Save my name, email, and website in this browser for the next time I comment. Δ DO YOU ENJOY MY BLOG? Support from readers like YOU keeps this blog running. Buying me a cup of coffee is a simple and affordable way to show your appreciation and help keep the posts coming! Buy Me a Coffee LINUX COMMANDS AND TOOLS How to Set or Change System Hostname in Linux 12 Ways to Find User Account Info and Login Details in Linux How to Install and Use Chrony in Linux 30 Ways to Validate Configuration Files or Scripts in Linux How to Delete Root Mails (Mailbox) File in Linux How to List All Files Ordered by Size in Linux LINUX SERVER MONITORING TOOLS 3 Tools to Monitor and Debug Disk I/O Performance in Linux Observium: A Complete Network Management and Monitoring System for RHEL/CentOS Monitor Server Logs in Real-Time with “Log.io” Tool on RHEL/CentOS 7/6 How to Monitor Ubuntu Performance Using Netdata How to Install Tripwire IDS (Intrusion Detection System) on Linux Installing “PHP Server Monitor” Tool using LEMP or LAMP Stack in Arch Linux LEARN LINUX TRICKS & TIPS Learn How to Set Your $PATH Variables Permanently in Linux Ternimal – Show Animated Lifeform in Your Linux Terminal How to Disable Shutdown and Reboot Commands in Linux How to Convert Files to UTF-8 Encoding in Linux How to Boot into Single User Mode in CentOS/RHEL 7 7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4) BEST LINUX TOOLS 5 Best Reference Management Software for Linux in 2024 My Favorite Command Line Editors for Linux – What’s Your Editor? 12 Best Java IDE’s for Linux Developers 7 Best Audio and Video Players for Gnome Desktop 10 Best File Comparison and Difference (Diff) Tools for Linux 5 Most Frequently Used Open Source Shells for Linux Privacy Manager Tecmint: Linux Howtos, Tutorials & Guides © 2024. All Rights Reserved. The material in this site cannot be republished either online or offline, without our permission. Hosting Sponsored by : Linode Cloud Hosting Search for: