Hello,
Thanks for your response. Can you give me an example of how to use fork to start a function in a perl module in the background?
Thank you. | [reply] |
if (my $pid = fork) {
# parent ($pid is process id of child)
parent_function();
} else {
# child
child_function();
exit;
}
Feel free to read perldoc -f fork, and look at some examples online. This is not really advanced perl, but it requires some attention. | [reply] [d/l] |
From personal experience, the exit is key. Let's just say that I'm glad that I had my own Sun workstation when I started experimenting with fork...*cough*fork bomb*cough*
thor
Feel the white light, the light within
Be your own disciple, fan the sparks of will
For all of us waiting, your kingdom will come
| [reply] |
Hello,
Remember to check for a fork error after forking:
if (my $pid = fork) {
## Parent
} elsif ($pid == 0) {
## Child
} else {
## Error, $pid is undefined
}
| [reply] [d/l] |