Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 24 lines (20 sloc) 0.597 kb
215d628 [examples/unix-fork.p6] a little bit of fun for at least the Linux users
Martin Berends authored
1 use v6;
2 use NativeCall;
3
37c4b61 @cxreg Passing no library name will resolve to the main program's symbol table
cxreg authored
4 sub fork() returns Int is native() { ... }
215d628 [examples/unix-fork.p6] a little bit of fun for at least the Linux users
Martin Berends authored
5
5e76b5e [examples/unix-fork.p6] drastically -Ofun the code
Martin Berends authored
6 my $children = 15;
7 for 1 .. $children -> $child {
8 my $pid = fork();
9 if $pid {
10 print "created child $child process $pid. ";
11 sleep 1; print "snore. ";
12 }
13 else {
14 for $child .. $children { sleep 1; print "yawn $child. "; }
15 exit 0;
16 }
215d628 [examples/unix-fork.p6] a little bit of fun for at least the Linux users
Martin Berends authored
17 }
18
19 # Notes:
5e76b5e [examples/unix-fork.p6] drastically -Ofun the code
Martin Berends authored
20 # * This code can hang your computer, depending on the number of
21 # children versus your real and virtual memory. For example, a 1GB
22 # netbook froze with 19 children.
23 # * Monitor your processes with a utility such as pstree or top.
Something went wrong with that request. Please try again.