Fork: Difference between revisions
Content added Content deleted
m (→{{header|Tcl}}: Rewrote for clarity () |
(Move 'Bash' to 'UNIX Shell' and port it to plain /bin/sh.) |
||
Line 63: | Line 63: | ||
Run, %A_AhkPath% "%A_ScriptFullPath%" |
Run, %A_AhkPath% "%A_ScriptFullPath%" |
||
MsgBox, 0, Fork, Stop this process.</lang> |
MsgBox, 0, Fork, Stop this process.</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|C}}== |
=={{header|C}}== |
||
Line 439: | Line 432: | ||
getpid is-data PID |
getpid is-data PID |
||
[ fork getpid PID = [ ." Child PID: " . cr ] [ ." In child\n" ] ifTrueFalse ] invoke</lang> |
[ 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 |
|||
⚫ | |||
⚫ | |||
i=$((i + 1)) |
|||
⚫ | |||
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}} |
|||
⚫ | |||
⚫ | |||
sleep 2 |
|||
echo "Parent process" |
|||
done</lang> |
|||
=={{header|UnixPipes}}== |
=={{header|UnixPipes}}== |