设置python进程名

设置python进程名,python,process,kill,Python,Process,Kill,我的python脚本需要每小时被删除一次,然后我需要重新启动它。我需要这样做,因为有时(我创建屏幕截图)可能会因为用户登录弹出窗口或其他原因而挂起浏览器窗口。。无论如何我创建了两个文件“reload.py”和“screenshot.py”。我通过cronjob运行reload.py 我以为这样会管用 # kill process if still running try : os.system("killall -9 screenshotTaker"); excep

我的python脚本需要每小时被删除一次,然后我需要重新启动它。我需要这样做,因为有时(我创建屏幕截图)可能会因为用户登录弹出窗口或其他原因而挂起浏览器窗口。。无论如何我创建了两个文件“reload.py”和“screenshot.py”。我通过cronjob运行reload.py

我以为这样会管用

    # kill process if still running
try :   
        os.system("killall -9 screenshotTaker");
except :
        print 'nothing to kill'

# reload or start process
os.execl("/path/to/script/screenshots.py", "screenshotTaker")
问题是,我读到的execl的第二个参数(给定的进程名)不起作用?我如何为它设置一个进程名以使kill起作用

提前谢谢

的第一个参数是可执行文件的路径。其余的参数将传递给该可执行文件,就像它们在命令行上键入的位置一样

如果您希望“screenshotTaker”成为流程的名称,那么这就是“screenshots.py”的职责。你在剧本里做了什么特别的事吗

顺便说一句,更常见的方法是跟踪(in/var/run/normal)正在运行的程序的PID。然后用PID杀死它。这可以通过Python(使用)在系统级完成,一些发行版提供了用于此目的的帮助程序。例如,在Debian上有
启动-停止守护进程
。以下是该男子的摘录:


我认为,
os.kill
会更好。可能是重复的,谢谢你的解释!我有一个数据库,有超过100万条网站名称的记录。我需要创建这些网站的截图,这发生在'screenshots.py'中,从数据库中获取记录并拍摄。。我会使用os.kill谢谢,但是我应该在screenshot.py中设置一个进程名?我该怎么做?我发现现在用python是不可能的?现在,我创建了一个小的变通方法。我将screenshots.py中的pid id存储到mysql数据库中。reload.py从数据库中获取pid id并终止/删除它。但是将进程名设置为kill by会更干净
start-stop-daemon(8)            dpkg utilities            start-stop-daemon(8)

NAME
       start-stop-daemon - start and stop system daemon programs

SYNOPSIS
       start-stop-daemon [options] command

DESCRIPTION
       start-stop-daemon  is  used  to control the creation and termination of
       system-level  processes.   Using   one   of   the   matching   options,
       start-stop-daemon  can  be  configured  to find existing instances of a
       running process.