LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-09-2006, 02:51 PM   #1
brazilian_user
Member
 
Registered: Nov 2005
Location: Brazil, Po - So Paulo
Distribution: Debian Etch
Posts: 110

Rep: Reputation: 15
Shell Script to kill a process automaticaly


Hello Guys!

Id like your help to solve a trouble in my system. I have two special process running in my server, each process consume about 400MB of RAM memory, sometimes this processes consume more than 400MB of memory and when this happens the service stops. Id like to create a shell script that always a process consume more than X MB this script kill the process aumomaticaly. Actually Id like a general ideia of how could I do this.

Thank you very much!!!
 
Old 06-09-2006, 04:16 PM   #2
Youri
Member
 
Registered: Oct 2004
Distribution: slamd64-current, slackware-current, clfs 6.1, arch-current, ubuntu dapper
Posts: 144

Rep: Reputation: 15
you can use a c script using sysctl to retrieve information and then the processes with the x mb usage their id can be retrieved and then u can kill them with killall
some info about sysctl http://www.hmug.org/man/3/sysctl.php
 
Old 06-09-2006, 04:17 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,447
Blog Entries: 54

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
...or simply use Monit.
 
Old 06-10-2006, 03:03 PM   #4
Youri
Member
 
Registered: Oct 2004
Distribution: slamd64-current, slackware-current, clfs 6.1, arch-current, ubuntu dapper
Posts: 144

Rep: Reputation: 15
works too :P
but he asked for an idea of a script i gave it :P
 
Old 06-10-2006, 07:39 PM   #5
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,447
Blog Entries: 54

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
but he asked for an idea of a script i gave it
You're quite right at that. Though sometimes it's good to give people solutions they couldn't have thought of. Reasons? OK:
0. I don't see any error-free scripting happening (esp. not with using sysctl, but OK),
1. C being faster compared to shell,
2. Monit is versatile,
3. Reinventing the wheel aint necessary,
4. I use it and I find it performs well (though that's no objective argument, OK).
 
Old 06-10-2006, 09:53 PM   #6
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
I'd suggesting fixing the process that's consuming 400Megs. Either it's eating the memory with a leak or by design, both of which can be corrected.
 
Old 06-11-2006, 12:32 AM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,983
Blog Entries: 11

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
crabboys suggestion aside (which is the most sensible ;]) I'd suggest
looking at ulimit ... something like 'ulimit -m 409600' should do the
trick for your problem quite nicely.


Cheers,
Tink
 
Old 06-11-2006, 05:19 AM   #8
Youri
Member
 
Registered: Oct 2004
Distribution: slamd64-current, slackware-current, clfs 6.1, arch-current, ubuntu dapper
Posts: 144

Rep: Reputation: 15
true

and
Quote:
Originally Posted by unSpawn
3. Reinventing the wheel aint necessary,
but its fun thats worth some right?
 
Old 06-11-2006, 06:15 PM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,447
Blog Entries: 54

Rep: Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890Reputation: 2890
but its fun | thats worth some right?
Definately.
 
Old 06-12-2006, 08:11 AM   #10
brazilian_user
Member
 
Registered: Nov 2005
Location: Brazil, Po - So Paulo
Distribution: Debian Etch
Posts: 110

Original Poster
Rep: Reputation: 15
Smile

Hello people!!

Im pleased your attention and effort on my issue, among the solutions you suggested to my Ive decided to use Monit. Its working well. For those that does not know it, please access this link, there is a very interesting article about Monit, it help me a lot, perhaps may be useful for you as well.

Thanks all you, thank you unSpawn
 
Old 06-12-2006, 11:04 AM   #11
fedora4002
Member
 
Registered: Mar 2004
Posts: 135

Rep: Reputation: 15
http://www.tildeslash.com/monit/
 
Old 06-12-2006, 09:09 PM   #12
brazilian_user
Member
 
Registered: Nov 2005
Location: Brazil, Po - So Paulo
Distribution: Debian Etch
Posts: 110

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by fedora4002
Ow My God. Thats it. Thank You fedora4002!
 
  


Reply


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
kill process and its child in a shell dalmassoc Linux - Software 4 03-03-2006 01:57 AM
why my script die itself when I try to kill a process?? jaimese Linux - Newbie 4 10-27-2005 05:50 AM
how do i kill a process from inside a bash script? mikaelo Programming 4 05-28-2004 08:51 AM
Kill a process launched by a shell script gsbarry Programming 7 01-06-2004 02:09 PM
script at xwin start to kill old process(es) butthead Programming 3 02-01-2002 08:39 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration