0
我在脚本中使用os.system()来调用shell命令。我写了一个示例脚本来了解os.system()如何执行命令。Python:了解os.system在linux和freeBSD上的行为
import os
os.system("sleep 20")
我跑一个FreeBSD和Linux机器上面的代码,然后做ps aux | grep sleep
,则结果如下:
FreeBSD的:
:~]# ps aux | grep sleep
root 94832 0.0 0.0 2768 984 0 S+ 5:31AM 0:00.00 sleep 20
的Linux(Ubuntu的) :
root 32726 0.0 0.0 4440 648 pts/2 S+ 01:01 0:00 sh -c sleep 20
root 32727 0.0 0.0 7192 612 pts/2 S+ 01:01 0:00 sleep 20
壳牌在这两台机器中都遭受打击。
由于os.system(cmd)
在子shell中执行cmd
,不应该有一个在freeBSD上运行的sh -c sleep 20
进程吗?有人可以解释这种行为吗?
'使用os.system()'本质上是'系统(3)'直通,所以你的答案将在那里。 –