#! perl5 #! /usr/local/bin/perl # # forx Dan Brockman 970617 Forks, execs to split parent from child # # Usage: forx command [ [arg] ... ] ################################################ # The author grants permission to use for any # # purpose, including copying and modification, # # provided the user acknowledges the author by # # name. # # -- Daniel Brockman, author, 20031220 # ################################################ # # Invokes, in background, command with arguments using system # calls "fork" and "exec" to separate parent and child processes. # # Sometimes when you invoke a process, even in background, # and then you try to log out, you will get a message about # "You have running jobs", and you can't log out. The ability of # a parent process to terminate before its children has similar # constraints in other circumstances. nohup is burdened with # bells and whistles and outputs inhibiting simple use. # forx enables simple use severing the invoked child process # from it's parent process. # ##if ( fork ) { # if I am the grandparent ## wait ; # wait for parent ##} else { # otherwise I am the parent ## if ( fork ) { # if I am the parent ## exit ; # suicide ## } else { # otherwise I am the child ## exec @ARGV ; # exec the command ## } # end if I am the parent ##} # end if I am the grandparent # # equivalent and faster... fork ? wait : ( fork ? exit : exec @ARGV ) ; #