Anonymous user
Fork: Difference between revisions
Move 'Bash' to 'UNIX Shell' and port it to plain /bin/sh.
m (→{{header|Tcl}}: Rewrote for clarity () |
(Move 'Bash' to 'UNIX Shell' and port it to plain /bin/sh.) |
||
Line 63:
Run, %A_AhkPath% "%A_ScriptFullPath%"
MsgBox, 0, Fork, Stop this process.</lang>
=={{header|Bash}}==▼
<lang bash>(for ((i=0;i<10;i++)); do sleep 1; echo "Child process"; done) &▼
for ((i=0;i<5;i++)); do▼
sleep 2▼
echo "Parent process"▼
done</lang>▼
=={{header|C}}==
Line 439 ⟶ 432:
getpid is-data PID
[ fork getpid PID = [ ." Child PID: " . cr ] [ ." In child\n" ] ifTrueFalse ] invoke</lang>
<lang bash>i=0
(while test $i -lt 10; do sleep 1; echo "Child process"; i=$((i + 1)); done) &
while test $i -lt 5; do
▲ sleep 2
▲ echo "Parent process"
i=$((i + 1))
▲done</lang>
This uses the operator <tt>&</tt> to run the child process and the parent process at the same time. The output for the next 10 seconds is "Child process" every 1 second, and "Parent process" every 2 seconds. Both processes inherit <tt>i=0</tt>, but each process has its own <tt>i</tt> variable because processes are independent.
The original version of this code used a bash for-loop.
{{works with|bash}}
▲<lang bash>(for ((i=0;i<10;i++)); do sleep 1; echo "Child process"; done) &
▲for ((i=0;i<5;i++)); do
sleep 2
echo "Parent process"
done</lang>
=={{header|UnixPipes}}==
|