Hi - I need to lauch a background process and get the pid. I had a look at a lot of post and they say to use fork and exec as follows:
#!/usr/bin/perl
use strict;
use warnings;
my $pid = fork;
if ((defined $pid) && ($pid == 0))
{
exec("sleep 30 >> /dev/null 2>&1 &");
exit;
}
print "child pid [$pid]\n";
However it does not give me the correct pid of the sleep program:
$ perl tst.pl
child pid [23367]
$ ps ax | grep sleep
23368 pts/7 S 0:00 sleep 30
23371 pts/7 S+ 0:00 grep --colour=auto sleep
How can I a launch a program and get its pid?