> But you don't need to call setsid() when you fork. Why
> looking for complicated workaround when you can do it
> properly without any workaround. Have you ever seen an
> example of fork that uses setsid?
Ok,
here is my confusion: I call the the long running process
from the modperl script with a system() call that was why I
was using the setsid() (in the longrunning process).
I have now changed the code my long running process to:
my($nOrgPID) = fork;
exit if $nOrgPID;
die "Could not fork: $!" unless defined $nOrgPID;
close STDIN;
close STDOUT;
close STDERR;
and that does not work, I have also tried putting it in the
modperl script instead but that doesn't work either.
What am I doing wrong and why would the setsid() be a
showstopper, especially as it is called after the close
statements (it doesn't reopen the filehandles does it).
I could understand that it would possibly be unnecessary, but
how could it stop this code from working?
Another (more detailed) run through.
1. modperl script starts long running process (lrp) with a
system() call.
2. lrp runs the code above (fork + close (tried this with
and without setsid)).
3. stop apache
4. start apache - fails (port in use)
5. netstat -na reveals port in LISTEN state.
6. kill lrp
7. netstat -na reveals port no longer in use.
8. start apache - now starts fine
I think I am doing something wrong somewhere, but I am not
sure where. Is it right that I have to do the system call and
the fork?
Kees