LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 02: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, 03:01 AM   #2
a4z
Senior Member
 
Registered: Feb 2009
Posts: 1,727

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

kill -9 1234

or

killall -9 programname
 
Old 01-28-2015, 04: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, 05:20 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 11,613

Rep: Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497
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, 08:43 AM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: MA, USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 7,231
Blog Entries: 12

Rep: Reputation: 2702Reputation: 2702Reputation: 2702Reputation: 2702Reputation: 2702Reputation: 2702Reputation: 2702Reputation: 2702Reputation: 2702Reputation: 2702Reputation: 2702
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 08:46 AM.
 
Old 01-29-2015, 08:51 AM   #6
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 11,613

Rep: Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497Reputation: 3497
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, 07:26 AM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,749

Rep: Reputation: 1302Reputation: 1302Reputation: 1302Reputation: 1302Reputation: 1302Reputation: 1302Reputation: 1302Reputation: 1302Reputation: 1302Reputation: 1302
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 09:26 AM
[SOLVED] infinite loop that isnt infinite? frieza Programming 2 10-27-2010 03:16 PM
Running 2 infinite loop scripts at startup cricri Linux - Server 19 08-24-2009 05:42 PM
Infinite Loop ewt3y Programming 3 08-16-2005 10:48 AM
infinite loop beginner_84 Programming 5 08-15-2004 03:32 AM

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

All times are GMT -5. The time now is 03:47 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration