挂载命令pid

发布于 2024-08-28 14:50:30 字数 194 浏览 7 评论 0原文

尝试挂载设备并获取挂载命令的 pid。

cmd="/bin/mount /dev/sda1 /mnt"

os.system(cmd)

现在如何获取mount命令的pid?我的系统上有很多可用的已安装设备,例如 ps | grep mount 不起作用。

Trying to mount a device and get the pid of mount command.

cmd="/bin/mount /dev/sda1 /mnt"

os.system(cmd)

Now how to obtain the pid of mount command? There plenty of mounted device available on my system, something like ps | grep mount won't work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2024-09-04 14:50:31

正如评论所暗示的,我不确定获取挂载 pid 有多大用处,但如果您使用 subprocess 模块,您可以轻松获取 pid。

>>> import subprocess
>>> p = subprocess.Popen("ls", shell=True)
>>> p.pid
4136
>>>

As the comments suggest I'm not sure how useful it is to get the mount pid, but if you use the subprocess module you can easily get the pid.

>>> import subprocess
>>> p = subprocess.Popen("ls", shell=True)
>>> p.pid
4136
>>>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文