Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(){
- while(1){
- printf("Infinite loopn");
- }
- return 0;
- }
- $ gcc loop.c -o loop.bin
- #!/usr/bin/perl
- use strict;
- use warnings;
- use POSIX ":sys_wait_h";
- use Time::HiRes qw(sleep);
- if(!defined( my $pid = fork())) {
- die "Cannot fork a child: $!";
- } elsif ($pid == 0) {
- print "Printed by child processn";
- system("./loop.bin");
- } else {
- print "Printed by parent processn";
- sleep(10);
- my $ret = waitpid($pid, WNOHANG);
- if ($ret == 0){
- kill ('KILL',$pid);
- sleep(1);
- }
- }
- Printed by child process
- Infinite loop
- Infinite loop
- Infinite loop
- Infinite loop
- Infinite loop
- Infinite loop
- Infinite loop
- Infinite loop
- ...
- ...
- ..
- ...
- } elsif ($pid == 0) {
- print "Printed by child processn";
- exec("./loop.bin");
- } else {
- ...
Add Comment
Please, Sign In to add comment