有没有一种方法可以确定Linux PID是否已暂停? [英] Is there a way to determine if a Linux PID is paused or not?

查看:100
本文介绍了有没有一种方法可以确定Linux PID是否已暂停?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python脚本,该脚本将SIGSTOP和.SIGCONT命令与os.kill一起使用来暂停或恢复进程.有没有办法确定相关的PID是处于暂停状态还是恢复状态?

I have a python script that is using the SIGSTOP and .SIGCONT commands with os.kill to pause or resume a process. Is there a way to determine whether the related PID is in the paused or resumed state?

推荐答案

您可以从/proc目录(/proc/<PID>)中找到有关进程的信息.具体来说,您可以使用以下python表达式找到其运行状态:

You can find information about a process from its /proc directory (/proc/<PID>). Specifically, you can find its run state with this python expression:

open(os.path.join('/proc', str(pid), 'stat')).readline().split()[2]=='T'

该下一个表达式修复了一个(可能是罕见的)原始错误:

This next expression fixes a (presumably rare) bug with the original:

re.sub(r'\(.*\)', '()', open(os.path.join('/proc', str(pid), 'stat')).readline()).split()[2]=='T'

这篇关于有没有一种方法可以确定Linux PID是否已暂停?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆