Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have a block of Perl code. I'm having some trouble understanding the same.

if(my $child = fork()) {
     #Do somthing
else {
     #Run system command

Could anyone please make me understand on What fork() does exactly in the above code?

share|improve this question

closed as off topic by Iain Mar 19 '13 at 7:53

Questions on Server Fault are expected to relate to server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Please do not post questions here because you are question banned on Stack Overflow. Please read carefully the information in this Q&A and comply with it's requirements. – Iain Mar 19 '13 at 7:58
Your stack doth runneth over. – Tom O'Connor Mar 19 '13 at 8:00

1 Answer 1

fork creates new child process.

It returns the child pid to/in the parent process, 0 to/in the child process, or undef if the fork is unsuccessful.

The code you posted executes #Do somthing in parent process and #Run system command in child process but it does not check for possible fork failure.


share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.