in reply to creating a fork process

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Re: creating a fork process
by fullyloaded (Initiate) on Feb 10, 2002 at 03:41 UTC
    sorry, i did read the manual before i asked my question but i dont seem to understand, i do try but im not that smart. i used your code in conjunction with what im doing...
    my $pid = fork; if ($pid) { # give thank u message. } elsif (defined $pid) { # close STDIN # close STDOUT # send emails. # exit. } else { # Error message. }
    but im not convinced a fork was created, because the browser seems to still be loading from the perl script the whole time while the emails are being sent and then it times out after about 5 minutes, i have closed both STDIN and STDOUT yet the perl script still seems to be communicating with the browser?
      This seems to word for me. Replace your "mail code" where I exec ('sleep 60')
      #!/usr/bin/perl -w use strict; use CGI; use Errno qw(EAGAIN); my $pid; my $page = new CGI; print $page->header(), $page->start_html(); FORK: { if ($pid = fork()) { print <<HTML; <CENTER> In the parent process<BR> HTML print $page->end_html(); exit; } elsif (defined $pid) { print <<HTML; <CENTER> In the child process<BR> HTML print $page->end_html(); close STDIN; close STDOUT; close STDERR; exec ('sleep 60'); exit; } elsif ($! == EAGAIN) { print qq(Re-doing fork\n); sleep 5; redo FORK; } else { die qq(Can't fork: $!'n); } }
      Hope this is of more help than the first posters comment. We all had to start once
        ok thanks for the code, i appreciate it! i have a couple of things...the last line which says

        die qq(Can't fork: $!'n); is the 'n suppose to be \n?

        i did run your code in conjunction with what im doing but i still had the same problem, the browser was still communicating with the perl script the whole time the emails were being sent, almost as if the fork wasnt actually sending the emails and the perl script was? i did overcome this by placing close STDIN, STDOUT, STDERR all inside the parent process, that completely cut the parent process from from everything and seems to have done the trick :) i suspect it may cause some other problem im unaware of?

        now that it seesm ive created a fork is there anyway to cancel a fork already in process?

        thanks rich

      You might want to take a look at Proc::Daemon. I think the init() function might be a better approach then the one you are taking with closing your filehandles.

Re: Re: creating a fork process
by ehdonhon (Curate) on Feb 12, 2002 at 10:38 UTC

    Jured,

    In answer to the question you posted in your update, I gave you a -- because you used the f-word in a way that made it sound like you were disgusted with the person for asking the question. I did not think that was appropriate for a message system dedicated to learning Perl. I understand how annoying it can be at times when people ask first and RTFM second. But if it was your intention to ask this person to read what is already available prior to posting, I think you did a poor job of it.

      i did look at the manual, but i didnt understand it, i am not the smartest programming in the world :( Thanks for the code coltsfoot, i appreciate it! i have a couple of things to ask though...the last line which says

      <code> die qq(Can't fork: $!'n); <code/>

      is the 'n suppose to be \n? i did run your code in conjunction with what im doing but i still had the same problem, the browser was still communicating with the perl script the whole time the emails were being sent, almost as if the fork wasnt actually sending the emails and the perl script was? i did overcome this by placing close STDIN, STDOUT, STDERR all inside the parent process, that completely cut the parent process from from everything and seems to have done the trick :) i suspect it may cause some other problem im unaware of? now that it seems ive created a fork is there anyway to cancel a fork already in process? thanks rich