Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Advice: Async Options for fire-and-forget subroutine

by mwb613 (Beadle)
on Oct 21, 2017 at 23:13 UTC ( [id://1201820]=note: print w/replies, xml ) Need Help??


in reply to Re: Advice: Async Options for fire-and-forget subroutine
in thread Advice: Async Options for fire-and-forget subroutine

Thanks Mom!

If I were a dumb person who'd never run any sort of forking before, should I just use fork? I also see forks, perlfork, many modules including the one you listed in your post. It sounds like, based on some of the things I'm reading, that my use case -- firing and forgetting -- will create zombies which I do not want considering it will be part of a long running process.

Also, just to clarify, the pid returned by fork() is the system PID (I'm running RHEL) or a Perl specific PID? If the former I could potentially stash the PIDs and kill them from a whole other process, no?

  • Comment on Re^2: Advice: Async Options for fire-and-forget subroutine

Replies are listed 'Best First'.
Re^3: Advice: Async Options for fire-and-forget subroutine
by Your Mother (Archbishop) on Oct 23, 2017 at 13:26 UTC

    Untested simplistic pseudocode that ignores a potential error point (0 == fork() is for the child side of the fork and it's not tested here). Forked processes are regular processes on *nix, just children of the original program.

    $SIG{CHLD} = "IGNORE"; while ( program_should_be_running() ) { # Might want a sleep or a usleep (from Time::HiRes) here. if ( my $pid = fork ) { # Do nothing...? This is the "permanent" parent process. # $pid is the child $$ } else { run_your_sub(); # Processes could stack up fast. } }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1201820]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-23 06:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found