[英]How can I start an external process in Perl?
I want to start a process, get its PID, and write it to a PID file. 我想启动一个进程,获取其PID,然后将其写入PID文件。 I then want to check that file, get the PID, and check if the process is running with
kill 0
. 然后,我想检查该文件,获取PID,并检查进程是否以
kill 0
运行。
If the process is not running, I want to start it, get its PID, and write it to the PID file. 如果该进程未在运行,我想启动它,获取其PID,然后将其写入PID文件。 If the process is already running, then I want to ignore it.
如果该进程已经在运行,那么我想忽略它。
How can I start a process so that it keeps running and I can check its status with Perl? 如何启动一个进程,使其保持运行状态,并可以使用Perl检查其状态?
It is traditional on UNIX for a process to manage its own PID file if it is understood that other processes will need its PID as a way to interact with it. 如果可以理解,其他进程将需要其PID作为与之交互的方式,则在UNIX上传统上是由一个进程管理自己的PID文件。
But.. If you use fork/exec to start the process, the parent receives the pid of the child process upon successful fork(). 但是..如果使用fork / exec启动进程,则在fork()成功后,父进程会收到子进程的pid。
If you give us more detail, we can give more precise help. 如果您给我们更多细节,我们可以提供更精确的帮助。
--------------------- 2014-11-04 ----------------- --------------------- 2014-11-04 -----------------
Your web services 'should' be creating their own PID files (Many commercially available server solutions do this already). 您的Web服务“应该”创建自己的PID文件(许多商用服务器解决方案已经这样做)。 But you don't say how those services are started, nor what kind of processes they are: apache, iis, node, websphere, etc.
但是您没有说这些服务是如何启动的,也没有说它们是什么样的过程:apache,iis,node,websphere等。
In general, this feels like an XY
problem. 通常,这感觉像是
XY
问题。 You tell us you want to do X
but the bogger picture is that you're doing Y
and there's a better way to to Y
than just doing X
. 您告诉我们您想做
X
但令人毛骨悚然的是,您在做Y
,比起做X
,有更好的方法到达Y
So please tell us about the environment and the software. 因此,请告诉我们有关环境和软件的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.