If you want your logging filehandle to avoid buffering, you have to disable it explicitly for that handle, not STDOUT (as you're doing now). I prefer the IO::Handle approach and lexical filehandles to select/$| mangling:
use IO::Handle; sub daemonize { my $log = shift; $log->autoflush( 1 ); # forking code goes here if ($pid > 0) { print {$log} "Forking Success. Child PID: $pid \n"; exit(); } print {$log} "Child Process Executing... \n"; setsid(); # ... }
Of course, if you've gone that far, it's not too far to use some sort of logging object that takes care of buffering/unbuffering and newlines for you, but that's more work than you suggested you need right now.
In reply to Re: forked child process is not able to access the file handle
by chromatic
in thread forked child process is not able to access the file handle
by shammi000
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |