LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 01-28-2015, 01:53 AM   #1
zama
Member
 
Registered: Mar 2012
Posts: 34

Rep: Reputation: Disabled
Killing programs running in infinite loop


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 .

Any help will be appreciated.
 
Old 01-28-2015, 02:01 AM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

Rep: Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742Reputation: 742
ps -A
look for the pid, eg 1234

kill -9 1234

or

killall -9 programname
 
Old 01-28-2015, 03:14 AM   #3
veerain
Senior Member
 
Registered: Mar 2005
Location: Earth bound to Helios
Distribution: Custom
Posts: 2,524

Rep: Reputation: 319Reputation: 319Reputation: 319Reputation: 319
May be using ulimit would help.
 
Old 01-28-2015, 04:20 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,241

Rep: Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836
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)
 
Old 01-29-2015, 07:43 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,788
Blog Entries: 13

Rep: Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831Reputation: 4831
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 View Post
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.

Last edited by rtmistler; 01-29-2015 at 07:46 AM.
 
Old 01-29-2015, 07:51 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 20,241

Rep: Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836Reputation: 6836
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).
 
Old 01-30-2015, 06:26 AM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Quote:
Originally Posted by veerain View Post
May be using ulimit would help.
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).
 
  


Reply

Tags
kill, ps


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
running infinite loop in kernel module karan2386 Linux - Kernel 5 04-20-2012 08:26 AM
[SOLVED] infinite loop that isnt infinite? frieza Programming 2 10-27-2010 02:16 PM
Running 2 infinite loop scripts at startup cricri Linux - Server 19 08-24-2009 04:42 PM
Infinite Loop ewt3y Programming 3 08-16-2005 09:48 AM
infinite loop beginner_84 Programming 5 08-15-2004 02:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration