Advertisement
Guest User

Untitled

a guest
Mar 27th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use warnings; use strict;
  3. use 5.012;
  4. use IPC::System::Simple qw(system);
  5.  
  6. system( 'xterm', '-geometry', '80x25-5-5', '-bg', 'green', '&' );
  7.  
  8. say "Hello";
  9. say "World";
  10.  
  11. system("cmd &")
  12.  
  13. $SIG{CHLD} = sub { wait };
  14.  
  15. $SIG{CHLD} = 'IGNORE';
  16.  
  17. unless ($pid = fork) {
  18. unless (fork) {
  19. exec "what you really wanna do";
  20. die "exec failed!";
  21. }
  22. exit 0;
  23. }
  24. waitpid($pid, 0);
  25.  
  26. system('xterm -geometry 80x25-5-5 -bg green &');
  27.  
  28. if (my $pid = fork) { #exits 0 = false for child process, at this point is brain split
  29. # parent ($pid is process id of child)
  30. #do something what you want, asynchronously with executed command
  31. waitpid($pid); #wait until child ends
  32. #if you don't want, don't wait. you process ends, then child process will be relinked
  33. #from your script to INIT process, and finally INIT will assume child finishing.
  34. #alternatively you can handle SIGCHLD signal in your script
  35. } else {
  36. # child
  37. exec('some_command arg1 arg2'); #or exec('some_command','arg1','arg2');
  38. #exit is not needed, because exec completly overwrites process content
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement