Pau*_*ker 6 process shell-script process-management
我怀疑这仅仅因为安全隐患是不可行的,但这是我想要做的。
基本上,我们在 CentOS 服务器上运行一个 bash shell 脚本,它调用Program-A
(在我们的例子中是 JMeter,但这是任意的),它运行并将数据转储到日志文件中。在该过程完成后,shell 脚本将启动Program-B
以分析日志。
我想做的是停止 的实例Program-A1
并将其替换为 的另一个实例Program-A2
,或者一些如何将它们交换到位的方法,以便我可以安全地结束Program-A1
而不会Program-B
过早启动。
我为什么要这样做?主要原因是它Program-A
在启动时加载了一些配置文件,如果我们对这些配置文件进行了更改,我们必须重新启动程序才能使它们生效,我想避免这种情况。
我知道这很可能是不可能的,但如果是,我将不胜感激。
编辑:我想我还不够清楚。基本上我的 shellscript 看起来像这样:
./Program-A
./Program-B
Run Code Online (Sandbox Code Playgroud)
当Program-A
完成转储到我们的日志时,Program-B
拿起日志并解析它。我遇到的问题是有时Program-A
的设置设置不正确或启动时环境有问题,这意味着我们需要再次运行整个过程。我们想避免仅通过更换我们的第一个实例Program-A
(调用它Program-A1
与一个新的实例)Program-A
(我们会打电话给这个Program-A2
)。这对每个人都更有意义吗?
我们想这样做的主要原因是因为Program-A
和Program-B
实际上是一个巨大的shell脚本,需要时间运行的一个组成部分。我们不想重新启动单个零件的整个过程,而是重新启动单个出现问题的程序。
It looks to me as if you are trying to replace a RUNNING process from OUTSIDE the process. That's some radical stuff.
When I first looked at the question, it seemed that you are looking exactly for exec
. But exec
is called by the program itself. So unless you have coded the process so that you can force it to just exec another process, you can't do that while it is running.
您可能会在程序 A 中创建一个信号陷阱exec
a program with predefined name (which you can then set to be whatever you want) and then use kill
on this process to force it to exec
. From the outside, it will look like the process kept running - it does, it just becomes someone else. However, if you haven't done that and you want to do this on a running process, I don't think you can do anything.
但是,如果外壳正在运行,但尚未启动关键进程,则只需替换有问题进程的文件即可。