This is a creation in Article, where the information may have evolved or changed.
Package Main
Import (
"OS"
"Os/exec"
"Path/filepath"
)
If OS. Getppid ()!=1{//Determine if it is a child process, and the child process will be taken over by system 1th process when the parent process return
Filepath,_:=filepath. Abs (OS. ARGS[0])//Convert the execution file path in the command line argument to the available path
Cmd:=exec.command (Filepath,os. Args[1:] ...) Passing other commands into the generated process
Cmd. Stdin=os. Stdin//sets the file descriptor for the new process and can be redirected to the file
Cmd. Stdout=os. Stdout
Cmd. Stderr=os. Stderr
Cmd. Start ()//Begin execution of new process without waiting for new process to exit
Return
}
This allows the daemon to be created and the semaphore can be accepted
A different way
If OS. Getppid ()!=1{
Args:=append ([]string{filepath},os. Args[1:] ...)
Os. StartProcess (Filepath,args,&os. Procattr{files:[]*os. File{os. Stdin,os. Stdout,os. Stderr}})
Return
}
You can also create daemons, which say startprocess is the lower interface, and CMD is an advanced interface
Actually, it can be lower.
PID, _, Syserr: = Syscall. Rawsyscall (Syscall. Sys_fork, 0, 0, 0)
If Syserr! = 0 {
Utils.logerr (Syserr)
Return
}
The go source is actually creating a new process.
Call the system function fork directly to generate a new process, just so do not know why the semaphore processing function is always not registered
So you can do it in either of the two ways.