A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
26
Task/Fork/Go/fork.go
Normal file
26
Task/Fork/Go/fork.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Printf("PID: %v\n", os.Getpid())
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("Done.")
|
||||
return
|
||||
}
|
||||
cp, err := os.StartProcess(os.Args[0], nil,
|
||||
&os.ProcAttr{Files: []*os.File{nil, os.Stdout}},
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
// Child process running independently at this point.
|
||||
// We have its PID and can print it.
|
||||
fmt.Printf("Child's PID: %v\n", cp.Pid)
|
||||
if _, err = cp.Wait(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue