http://www.perlmonks.org?node_id=11133393


in reply to perl scripting help

Taking it a little further and daemonizing, etc...

#!/usr/bin/env perl use common::sense; use POSIX qw//; defined (my $pid = fork()) or die "Can't fork: $!"; exit if $pid; chdir "$ENV{HOME}" or die "Can't chdir $ENV{HOME}"; POSIX::setsid or die "setsid: $!"; close STDOUT; close STDIN; close STDERR; open STDIN, '<', "/dev/null" or die "open: $!"; open STDOUT, '>', "/dev/null" or die "open: $!"; open STDERR, '>', "/dev/null" or die "open: $!"; defined ($pid = fork()) or die "Can't fork: $!"; if ($pid) { waitpid $pid, 0; } else { eval { my @cmd = ( '/usr/X11R6/bin/xterm', '-e', '/bin/sh -c "find . | xargs egrep "perl""', #simulate module loading ); exec @cmd; }; warn $@ if $@; exit 1; }