gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
python判断linux服务器进程是否存在
- User
python判断linux服务器进程是否存在
- Assistant
可以使用psutil库来实现Python判断Linux服务器进程是否存在的功能。
安装psutil库:
pip install psutil代码:
import psutil def check_process_exists(process_name): """ 判断进程是否存在,存在返回True,否则返回False """ for proc in psutil.process_iter(): try: pinfo = proc.as_dict(attrs=['name']) except psutil.NoSuchProcess: pass else: if process_name == pinfo['name']: return True return False # 调用check_process_exists函数判断指定进程是否存在 if check_process_exists('进程名'): print('进程存在') else: print('进程不存在')
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.