Fork: Difference between revisions

749 bytes added ,  13 years ago
Go solution
(Move 'Bash' to 'UNIX Shell' and port it to plain /bin/sh.)
(Go solution)
Line 163:
 
[ "Hello form child" print flush 0 _exit ] [ drop "Hi from parent" print flush ] with-fork</lang>
=={{header|Go}}==
This program prints its own pid, then runs a copy of itself if given any argument on the command line. When it does so, it prints the pid of the child process it started. Output should show this pid matching the child's self reported pid.
<lang go>package main
 
import (
"exec"
"fmt"
"os"
)
 
func main() {
fmt.Println("pid:", os.Getpid())
if len(os.Args) < 2 {
fmt.Println("done")
return
}
c, err := exec.Run(os.Args[0], nil, nil, "",
exec.PassThrough, exec.PassThrough, exec.PassThrough)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("child pid:", c.Process.Pid)
}</lang>
Output:
<pre>
pid: 26681
child pid: 26682
> pid: 26682
done
</pre>
 
=={{header|Haskell}}==
<lang haskell>import System.Posix.Process
1,707

edits