本文整理汇总了Golang中syscall.ProcAttr.Files方法的典型用法代码示例。如果您正苦于以下问题:Golang ProcAttr.Files方法的具体用法?Golang ProcAttr.Files怎么用?Golang ProcAttr.Files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类syscall.ProcAttr
的用法示例。
在下文中一共展示了ProcAttr.Files方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: forker
// setup and fork/exec myself. Make sure to keep open important FD's that won't get re-created by the child
// specifically, std* and your listen socket
func forker(srv *falcore.Server) (pid int, err int) {
fmt.Printf("Forking now with socket: %v\n", srv.SocketFd())
mypath := os.Args[0]
args := []string{mypath, "-socket", fmt.Sprintf("%v", srv.SocketFd())}
attr := new(syscall.ProcAttr)
attr.Files = append([]int(nil), 0, 1, 2, srv.SocketFd())
pid, err = syscall.ForkExec(mypath, args, attr)
return
}
示例2: pwinput
func pwinput(prompt string) (pw string, err error) {
fmt.Print(prompt)
cmd := "/bin/stty"
args := []string{"stty", "-echo"}
fd := []uintptr{uintptr(syscall.Stdin), uintptr(syscall.Stdout), uintptr(syscall.Stderr)}
proc := new(syscall.ProcAttr)
proc.Files = fd
_, err = syscall.ForkExec(cmd, args, proc)
if err != nil {
return pw, errors.New("failed forkexec")
}
bytes := make([]byte, 1000)
os.Stdin.Read(bytes)
pw = strings.TrimRight(string(bytes), string([]byte{0}))
pw = strings.TrimRight(pw, "\n")
return
}
示例3: forker
// setup and fork/exec myself. Make sure to keep open important FD's that won't get re-created by the child
// specifically, std* and your listen socket
func forker(srv *falcore.Server) (pid int, err error) {
var socket string
// At version 1.0.3 the socket FD behavior changed and the fork socket is always 3
// 0 = stdin, 1 = stdout, 2 = stderr, 3 = acceptor socket
// This is because the ForkExec dups all the saved FDs down to
// start at 0. This is also why you MUST include 0,1,2 in the
// attr.Files
if goVersion103OrAbove() {
socket = "3"
} else {
socket = fmt.Sprintf("%v", srv.SocketFd())
}
fmt.Printf("Forking now with socket: %v\n", socket)
mypath := os.Args[0]
args := []string{mypath, "-socket", socket}
attr := new(syscall.ProcAttr)
attr.Files = append([]uintptr(nil), 0, 1, 2, uintptr(srv.SocketFd()))
pid, err = syscall.ForkExec(mypath, args, attr)
return
}
示例4: main
func main() {
start := time.Now()
args := os.Args
if len(args) == 1 {
var attr syscall.ProcAttr
var sattr syscall.SysProcAttr
attr.Files = []uintptr{uintptr(syscall.Stdin), uintptr(syscall.Stdout), uintptr(syscall.Stderr)}
attr.Sys = &sattr
now := time.Now()
_, err := syscall.ForkExec("Exec", []string{"Exec", "dont"}, &attr)
if err != nil {
fmt.Printf("Err: %v\n", err)
}
fmt.Printf("Parent: %v\n", now)
} else {
fmt.Printf("Child: %v\n", start)
}
}
示例5: Spawn
func Spawn(tokens []string) (int, error) {
cmd, lookError := exec.LookPath(tokens[0])
if lookError != nil {
log.Printf("[ERROR] [process] Spawn.exec.LookPath(%s) >>> %s\n", tokens[0], lookError)
return 0, lookError
}
var sys_attr syscall.SysProcAttr
var proc_attr syscall.ProcAttr
proc_attr.Sys = &sys_attr
proc_attr.Env = os.Environ()
proc_attr.Files = []uintptr{uintptr(syscall.Stdin),
uintptr(syscall.Stdout),
uintptr(syscall.Stderr)}
pid, forkError := syscall.ForkExec(cmd, tokens, &proc_attr)
if forkError != nil {
log.Printf("[ERROR] [process] Spwan.syscall.ForkExec(%s) >>> %s\n", cmd, forkError)
return 0, forkError
}
return pid, nil
}