Discuss / Python / 第一个例子是有错误还是我理解不当?

第一个例子是有错误还是我理解不当?

Topic source

ChuckyYan

#1 Created at ... [Delete] [Delete and Lock User]

print('I am child process (%s) and my parent is %s.' % (os.getpid(), os.getppid())) 结果:I am child process (877) and my parent is 876.

变量都是os.getpid(),为什么结果会不同?

应该是 print('I am child process (%s) and my parent is %s.' % (pid, os.getppid()) 这样吗?

父子进程的概念你理解的对

父子进程的概念你理解的不对

print('I am child process (%s) and my parent is %s.' % (os.getpid(), os.getppid()))

第一个是os.getpid(),第二个是os.getppid() 一个是PID,是自己的, 一个是PPID,是父进程的。


  • 1

Reply