fork a new process in perl
2011-01-27
147 words
1 min read
I was doing something today and found that I require to fork a new process in perl. Now I had never done this earlier, so I did not know how to do this.
First some background :
I was doing some program very similar to http server, where the script accepts some input through a socket and then processes the same. In doing so I was seeing that the script was taking some time in processing the input and thus was not processing the second request until the first one was completed. Simple solution, fork the process.
[cc lang=”perl”]
$pid=fork();
if (! $fork)
{
do the child processing
exit
}
else
{
do the parent processing
exit
}
Related articles
- Given/when – The Perl switch statement (transfixedbutnotdead.com)
- How to Identify a Good Perl Programmer (modernperlbooks.com)
- A Timely Start – Perl.com (perl.com)
- Why I Stuck With Perl (blogs.perl.org)
Related Articles:
- 2010/05/24 Inotify Example - Introduction to Inotify with a C Program Example
- 2010/04/28 String and Array Creation
- 2010/03/24 Recursive Regular Expressions
- 2010/09/15 cURL – Tutorial
- 2010/05/30 Google\’s RE2 regular expression library
Authored By Amit Agarwal
Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.