sleep between system calls

D

dwmyers

I have a task that runs as follows:

1) examine a daemon in memory for size usage. If it gets beyond a
certain size, kill it.
2) wait a while
3) restart the process.

I'm trying with a bit of code like this:

system("pkill -9 foo");
sleep 10;
system("/etc/init.d/foo start");

Only problem is, the sleep isn't working, and the process isn't
restarting. I tend to think the first system call must be returning
signals that kill the sleep, but I'm not deep enough into the internals
to know.

If you have any ideas, I'm interested.

David.
 
X

xhoster

I have a task that runs as follows:

1) examine a daemon in memory for size usage. If it gets beyond a
certain size, kill it.
2) wait a while
3) restart the process.

I'm trying with a bit of code like this:

system("pkill -9 foo");
sleep 10;
system("/etc/init.d/foo start");

Only problem is, the sleep isn't working, and the process isn't
restarting.

That sounds like two different problems, and "isn't working" is the worst
description ever.
I tend to think the first system call must be returning
signals that kill the sleep, but I'm not deep enough into the internals
to know.

If you have any ideas, I'm interested.

Ask perl for help. Are you using strict and warnings?

system("pkill -9 foo") and die "$!";
warn "slept for ", sleep 10;
system("/etc/init.d/foo start") and die "$!";

Xho
 
I

Ian Wilson

That sounds like two different problems, and "isn't working" is the worst
description ever.




Ask perl for help. Are you using strict and warnings?

system("pkill -9 foo") and die "$!";
warn "slept for ", sleep 10;
system("/etc/init.d/foo start") and die "$!";

s/and/or/ or please_explain();

Thanks.
 
I

Ian Wilson

sub please_explain {
system "perldoc -f system";
};

alias perldoc='echo "Thrrrrp"'

but thanks anyway, I must try to be less lazy in future.

Paul's
system("pkill -9 foo") and die "$!";

is more succinct than perldoc's
system("pkill -9 foo") == 0 or die "$!";

but I think the perldoc's construction is more successful at flagging
that the principle of least surprise is being necessarily broken a
little. That's my excuse anyway.
 
D

dwmyers

That sounds like two different problems, and "isn't working" is the worst
description ever.


Ask perl for help. Are you using strict and warnings?

system("pkill -9 foo") and die "$!";
warn "slept for ", sleep 10;
system("/etc/init.d/foo start") and die "$!";


Strict and Warnings are in use. Didn't receive any warnings though. I
am going to borrow this 3 line rewrite and see if it gives me more
info.

~~~ 5 minutes later ~~~

And lo and behold, found the issue. script itself was named $foo .
'_check', so it was killing $foo and itself. hence, no sleep.

Thanks,

David.
 
A

A. Sinan Unur

(e-mail address removed) wrote in
Strict and Warnings are in use.

That should be

use strict;
use warnings;

Case matters, even on a case-insensitive file system.

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,157
Latest member
MercedesE4
Top