How to count how many processes opened by fork function in perl.
Recently I faced an technical interview in a reputed IT firm.
the interviewer asked me about how many processes will be created if the following 3 different fork system call invocations are given:
The answer to first was obvious 2 processes.
2nd one will start 3 processes.
bt the 3rd I told was 5 processes, the interviewer disagreed and said its
When running the below code which uses Parallel::ForkManager I get two sleep processes and not one as expected.
18748 pts/2 S+ 0:00 /usr/bin/perl ./fork.pl
18749 pts/2 S+ 0:00 /usr/bin/perl ./fork.pl
18750 pts/2 S+ 0:00 sleep 12345
18751 pts/2 S+ 0:00 sleep 12345
And also it doesn't execute the print commands until the sleep command exits.