Guest User

Untitled

a guest
May 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. int main(){
  3.  
  4. while(1){
  5. printf("Infinite loopn");
  6. }
  7.  
  8. return 0;
  9. }
  10.  
  11.  
  12. $ gcc loop.c -o loop.bin
  13.  
  14. #!/usr/bin/perl
  15.  
  16. use strict;
  17. use warnings;
  18. use POSIX ":sys_wait_h";
  19. use Time::HiRes qw(sleep);
  20.  
  21. if(!defined( my $pid = fork())) {
  22. die "Cannot fork a child: $!";
  23. } elsif ($pid == 0) {
  24. print "Printed by child processn";
  25. system("./loop.bin");
  26. } else {
  27. print "Printed by parent processn";
  28. sleep(10);
  29. my $ret = waitpid($pid, WNOHANG);
  30.  
  31. if ($ret == 0){
  32. kill ('KILL',$pid);
  33. sleep(1);
  34. }
  35. }
  36.  
  37. Printed by child process
  38. Infinite loop
  39. Infinite loop
  40. Infinite loop
  41. Infinite loop
  42. Infinite loop
  43. Infinite loop
  44. Infinite loop
  45. Infinite loop
  46. ...
  47. ...
  48. ..
  49.  
  50. ...
  51. } elsif ($pid == 0) {
  52. print "Printed by child processn";
  53. exec("./loop.bin");
  54. } else {
  55. ...
Add Comment
Please, Sign In to add comment