Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

using Proc::ProcessTable::Process

by aijin (Monk)
on Jul 06, 2001 at 00:42 UTC ( #94269=perlquestion: print w/ replies, xml ) Need Help??
aijin has asked for the wisdom of the Perl Monks concerning the following question:

I'm working on a script that runs a shell command that may occassionally run awry and generate huge amounts of looping data. What I'm trying to figure out is how to monitor the size of the data generated and kill the process if it hits above x bytes.

The problem is that this command doesn't feed back the data as it generates it, but waits until the end and sends it all back in a hash. So I'm taking a look at Proc::ProcessTable::Process. It has a command size which returns the process' virtual memory in bytes.

Is this what I need? I'm not all that knowledgable with the inner workings of these machines. There's another command called rss which returns the resident set size, but I have no idea what that is, and the virtual memory command seems to be more likely the right choice.

-aijin

Comment on using Proc::ProcessTable::Process
Select or Download Code
Re: using Proc::ProcessTable::Process
by bluto (Curate) on Jul 06, 2001 at 01:33 UTC
    It's pretty crude to kill a process because it gets too big. Any Unix-like OS worth it's salt will do this for you usually on a user-id basis (man ulimit). Probably not the best way to go if you can avoid it.

    One thing that I'm not too clear on is that you say the process is returning all of the output at once as a hash. How does it do this? Perl hashes are typically converted into some kind of output stream (printed to a temp file, sent as text over a pipe, etc) before they can be sent to another process.

    Also, is the other process really saving everything to the very end before it writes the output, or is the receiving process slurping in the output all at once...

    $all_the_output = `my_shell_command`;
    If this is what is going on, you may want to try reading from a pipe instead...
    $pid = open(PIPE, "my_shell_command |") or die; while ($line = <PIPE>) { if ($i_received_too_much_garbage) { kill $my_favorite_signal => $pid; } } ...
    bluto

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://94269]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2014-09-23 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (210 votes), past polls