[SOLVED] Killing programs running in infinite loop
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a server which is being used by students to write C , C++ programs . Many of the times it happens that some of the programs runs in infinite loop causing the system to crash . I want to identify these programs running in infinite loop to kill them . But ps command seems does not display the program name , it only displays 'bash' . Killing bash process is not the solution for me . Is there any way to identify these C programs to kill them .
ps -ef can be used too, but do not use kill -9, a simple kill program would be enough.
In some cases you can try pgrep or even pkill program (see man page about usage and flags)
As far as detecting the processes by user, because when you use something like ps -ef you'll see every process on the system, you can use something like ps -e -U <username> to detect processes by a specific user.
Quote:
Originally Posted by pan64
ps -ef can be used too, but do not use kill -9, a simple kill program would be enough.
In some cases you can try pgrep or even pkill program (see man page about usage and flags)
So it sends SIGTERM versus SIGKILL what's the big deal? I do agree that I use kill with the default or pkill, again the default signal there is TERM, but if the offending process don't go away, I give it a -9 which cannot be blocked.
Quote:
SYNOPSIS
kill [ -signal | -s signal ] pid ...
DESCRIPTION
The default signal for kill is TERM. Use -l or -L to list available signals.
that is about exit and/or abort the program. In normal/usual cases the apps have signal handler and able to catch them and therefore able to do some cleanup before exiting (that is valid for sigterm and other signals, but not for sigkill). Sigkill means the app will not get more time to run, the inodes will not be closed properly, temp files will not be removed ...
So use -9 only as a last chance (not really, this is the last but one, the real last is to reboot).
This is really the solution. When a process uses up its CPU/memory resource it will get aborted automatically.
All the others require you to first be able to login and hunt for the process to terminate. If the system is already over saturated (either by CPU or swap thrashing), you won't get logged in.
This is also what some systems use cgroups for. Each user is put into their own cgroup, and that provides a global sharing that one user process cannot hog. This is a method of "fair share" scheduling that guarantees a user a share of the system - and if there are more users, the share gets smaller (the "fair" part of it).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.