Hi Monks,
I'm writing a script that functions a deamon to start and watch over other processes. That is, you can tell the daemon to start some other process (e.g. "ls -lh /var/www/html" or something) and it will fork it off as a child and tell you when it's done. The daemon stays running 24/7. You can also tell it to kill a process that it has started. The way I currently have things set up, the code looks something like this:
my $pid = fork();
if ($pid == 0) {
#this is the child
exec("$command_you_requested_me_to_start") or die "Couldn't start
+!\n";
} elseif (!defined($pid)){
#some sort of error occured...say so and die
print "ERROR!\n";
exit;
}
Then when I try to kill a process that I've started, I use code something like this:
my $attempt = kill('INT', $pid_of_child_process);
Unfortunately when I do this, the child process I've tried to kill simply becomes a zombie process and don't go away until the daemon script exits. I tried using 'KILL' instead of 'INT' and also played briefly with 'CHLD' and 'SIG_IGN' but got the same results.
Can anyone show me a better way to start/kill these child processes? It would be best if I could use SIGINT for the killing part, since some of the processes will be catching SIGINT and exiting gracefully accordingly....
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.