chrome has asked for the wisdom of the Perl Monks concerning the following question:
Hi superMonks,
I'm trying to write a program, actually a daemon, which stay in memory and perform something like tail -F on a rapidly updated log file. Then the program, when detect a new line on the file, have to launch another compiled perl script which will perform some operations on the log line and then send it with a post.
To clearly explain, I will refer to these two program as "prgTAIL" and "prgPROCESS". So, prgTAIL tail the log and launch prgPROCESS passing the new line to it.
Obviously the prgTAIL doesn't have to wait for the prgPROCESS to end the process, cause prgTAIL have to stay in memory and keep detecting new line on the log. Also, the rate of file update needs to launch multiple parallel prgPROCESS instance. For this reason I'm using two program: the first small and fast just pass the data to the second, which may be heavier cause it can be launched in multiple instances.
On the prgTAIL I used:
- a pipe to tail the log file
- a while loop to launch prgPROCESS on new log line
- a fork(); to continue without waiting prgPROCESS ends
my $log_csv = "/log/csv.csv"; open (my $pipe, "-|", "tail", "-n0", "-F", $log_csv) or die "error"; while (<$pipe>) { $line = $_ ; my $pid = fork(); if (defined $pid && $pid == 0) { exec("/bin/prgPROCESS ".$line) ; # I tried system() too. exit 0; } }
The prgPROCESS operation are not so important; anyway.. it parses the $line passed as arguments, construct an XML and then post it via https.
So, this stuff actually run, but I think I messed up something with the process, cause when a reach a number of newline and prgPROCESS call around 550, prgTAIL keep running but it can't call prgPROCESS anymore, cause there are too many process. I get this error on the bash:
-bash: fork: Resource temporarily unavailableWhat's wrong? Any idea? Maybe the prgPROCESS processes don't end and stay stuck without make room for other process?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: A daemon to tail a log and fork multiple external (perl) script
by BrowserUk (Patriarch) on Nov 19, 2015 at 05:19 UTC | |
|
Re: A daemon to tail a log and fork multiple external (perl) script
by afoken (Chancellor) on Nov 19, 2015 at 18:50 UTC |