Created
July 16, 2012 04:35
-
-
Save keiya/3120584 to your computer and use it in GitHub Desktop.
Process watchdog script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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