Tell me more ×
Server Fault is a question and answer site for professional 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
     return;
}

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

share|improve this 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 at 7:58
Your stack doth runneth over. – Tom O'Connor Mar 19 at 8:00

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

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined in the FAQ. 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 closed questions here.

1 Answer

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.

URL(s):

share|improve this answer

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