in reply to Im I forking properly ?
So, no, you're not doing it properly.
I was hoping that some other monk would tell you that more politely, but no one did, so I'm just telling you like it is.As for what is wrong: $output and $fver are not declared anywhere, so use strict aborts compilation. wait in a SIGCHLD handler is just wrong, because it waits only for one child, but:
... when the signal is delivered to the process by the system (to the C code that implements Perl) a flag is set, and the handler returns immediately.
Then at strategic "safe" points in the Perl interpreter (e.g. when it is about to execute a new opcode) the flags are checked and the Perl level handler from %SIG is executed.
...
As the Perl interpreter looks at signal flags only when it is about to execute a new opcode, a signal that arrives during a long-running opcode (e.g. a regular expression operation on a very large string) will not be seen until the current opcode completes.
If a signal of any given type fires multiple times during an opcode (such as from a fine-grained timer), the handler for that signal will be called only once, after the opcode completes; all other instances will be discarded.
In addition, the flag-setting handler in perl blocks SIGCHLD signal while it's executing; and only one blocking signal can be pending, so, if two or more children die during that, you'll get at least one zombie.
Recommended fix:
Recommended reading:$SIG{CHLD} = 'IGNORE';
Also, see "The Linux Programming Interface", chapters 20-22 (applicable to all Unix-like systems, not only Linux).perldoc perlstyle perldoc strict perldoc perlipc man 7 signal man 2 wait man 2 sigaction perldoc -f wait perldoc -v '%SIG'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Im I forking properly ?
by leostereo (Beadle) on Apr 18, 2016 at 14:45 UTC | |
|
Re^2: Im I forking properly ?
by leostereo (Beadle) on Apr 18, 2016 at 14:50 UTC | |
by Athanasius (Archbishop) on Apr 19, 2016 at 07:00 UTC |