go pid tid
PID(process ID): 进程ID
PPID(parent process ID):父进程ID号
PGID(Process Group ID 进程组 ID号)
TGID(Thread Group ID): 线程组ID号
SID(Session ID): 会话ID。在shell支持工作控制(job control)的前提下,多个进程组还可以构成一个会话。
TID(Thread ID): 线程ID
package main import ( "fmt" "golang.org/x/sys/unix" "time" ) func see(s string) { getid("see " + s) } func getid(s string) { pid := unix.Getpid() fmt.Println(s+" Getpid", pid) fmt.Println(s+" Gettid", unix.Gettid()) fmt.Println(s+" Getppid", unix.Getppid()) pgid, _ := unix.Getpgid(pid) fmt.Println(s+" Getpgid", pgid) sid, _ := unix.Getsid(pid) fmt.Println(s+" Getsid", sid) /* fmt.Println(s+" Getegid", unix.Getegid()) fmt.Println(s+" Geteuid", unix.Geteuid()) fmt.Println(s+" Getgid", unix.Getgid()) fmt.Println(s+" Getuid", unix.Getuid()) */ } func main() { go see("hello") go see("world") getid("main") time.Sleep(1 * time.Second) }
cts@cts-pc:~/test$ ./test main Getpid 29402 main Gettid 29402 main Getppid 28599 main Getpgid 29402 main Getsid 28599 see hello Getpid 29402 see hello Gettid 29406 see hello Getppid 28599 see hello Getpgid 29402 see hello Getsid 28599 see world Getpid 29402 see world Gettid 29405 see world Getppid 28599 see world Getpgid 29402 see world Getsid 28599

浙公网安备 33010602011771号