简体   繁体   English

如何在Perl中启动外部过程?

[英]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.

相关问题 如何从Perl将参数传递给外部进程? - How can I pass arguments to an external process from Perl? 如何使用Perl启动远程进程而不等待它完成? - How can I use Perl to start a remote process and not wait for it to finish? 我如何有一个Perl / Tk进度条来显示外部进程正在运行? - How can I have a Perl/Tk progress bar showing that an external process is running? 如何在不等待Perl CGI脚本完成的情况下运行外部进程? - How can I run an external process without waiting for it to finish from a Perl CGI script? 如何使用 perl 和 Net::OpenSSH 在远程机器上启动后台进程? - How can I start a background process on a remote machine using perl and Net::OpenSSH? 如何在Perl中运行外部程序? - How can I run an external program in Perl? 如何在Perl中解雇一个进程? - How can I fire and forget a process in Perl? 如何为 Perl 启动交互式控制台? - How can I start an interactive console for Perl? 是否有一个perl模块可以启动进程并将三个主I / O句柄返回到该进程? - Is there a perl module that can start a process and return the three main I/O handles to that process? 你如何在Perl中启动后台进程? - How do you start a background process in Perl?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM