Skip to content

Instantly share code, notes, and snippets.

@keiya
Created July 16, 2012 04:35
Show Gist options
  • Select an option

  • Save keiya/3120584 to your computer and use it in GitHub Desktop.

Select an option

Save keiya/3120584 to your computer and use it in GitHub Desktop.
Process watchdog script
#!/usr/bin/perl --
# process watchdog script
# Keiya Chinen <[email protected]>
use strict;
use warnings;
$| = 1;
my $cmd_line = '/home/keiya/cast_mp4/sc_serv sc_serv_basic.conf';
my $i = 1;
while (1) {
print "[$0]<$i>calling fork_exec";
&fork_exec();
$i++;
}
sub fork_exec {
my $pid = fork;
die "Cannot fork: $!" unless defined $pid;
if ( $pid ) {
print "[$0]parent($$) forked a child($pid)\n";
waitpid($pid,0);
print "[$0]child($pid) died\n";
}
else {
sleep 1;
# fork-exec
print "[$0]child($$) will exec \"$cmd_line\"\n";
exec($cmd_line);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment