Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: confusing fork/readline behaviour

by roboticus (Chancellor)
on Aug 14, 2015 at 14:29 UTC ( #1138588=note: print w/replies, xml ) Need Help??


in reply to Re: confusing fork/readline behaviour
in thread confusing fork/readline behaviour

Not completely true. Using fork is a natural way to perform processes in the background.

$ cat forkit.pl #!/usr/bin/env perl use strict; use warnings; my $pid = fork(); if ($pid) { print "Parent is exiting now!\n"; } else { print "Child is waiting a bit\n"; sleep 15; print "Child is done!\n"; } $ perl forkit.pl Parent is exiting now! Child is waiting a bit $ date Fri Aug 14 10:22:06 EDT 2015 $ date Fri Aug 14 10:22:15 EDT 2015 $ Child is done!

There are differences on different operating systems, to be sure. Some processes could be killed on some operating systems (though I've not experienced it myself). You can accumulate zombie processes if you don't take steps to avoid it. If you're going to use fork, you need to educate yourself on what it does and doesn't do on your platform.

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Replies are listed 'Best First'.
Re^3: confusing fork/readline behaviour
by (anonymized user) (Curate) on Aug 14, 2015 at 19:01 UTC
    Yes that's true. Although it is more common that the parent has more work to do, it is also a well-known way to create a daemon by having a main program fork and exit immediately, leaving the child running detached.

    One world, one people

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2020-02-28 16:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (125 votes). Check out past polls.

    Notices?