in reply to Re: How do you launch a background process and get pid?
in thread How do you launch a background process and get pid?

Thanks. I found this thread for suppressing the output:http://www.perlmonks.org/?node_id=53870 The code now looks like this:
#!/usr/bin/perl use strict; use warnings; my $pid = fork; if ((defined $pid) && ($pid == 0)) { open(STDOUT, "/dev/null"); # suppressing output open(STDERR, "/dev/null"); # suppressing output exec("sleep", "30"); exit; } print "child pid [$pid]\n";

Replies are listed 'Best First'.
Re^3: How do you launch a background process and get pid?
by afoken (Chancellor) on Apr 18, 2016 at 17:12 UTC
    open(STDOUT, "/dev/null"); # suppressing output open(STDERR, "/dev/null"); # suppressing output

    Yes, this suppresses output, but accidentally. You open STDOUT and STDERR for input. That may confuse your child process. What you really want is the three-argument form of open, used for output:

    open STDOUT,'>','/dev/null'; open STDERR,'>','/dev/null';

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)