English 中文(简体)
我如何监测两个进程,如果一个撤出(现金描述)则做些什么?
原标题:How do I monitor two processes & do something if one exits (bash scripting)?

I m 试图用双管书写包裹,使启动和关闭三个方案自动化。

#!/bin/bash
gnome-screensaver-command -i -n aeolus-wrapper.sh &
aeolus &
qjackctl

在他们开始后,我需要监测奥古斯托和劫持车,并杀死剩余的两个过程,如果他们要么是陈旧的,要么是劫持的:

# if aeolus exits, kill gnome-screensaver-command and qjackctl
# if qjackctl exits, kill gnome-screensaver-command and aeolus

这是我 st的。 引自。 任何建议都受到欢迎。

最佳回答

不要使用 while。 只是一个障碍,等待一个特别小组告诉你,其中一个进程已经终止。 在陷阱中,杀死了剩余的运行过程。 例如:

#!/bin/bash

set -m
trap  list=$( jobs -rp ); test -n "$list" && kill $list  CHLD
cmd1 &
cmd2 &
cmd3 &
wait

This will run 3 commands. When one exits, the other two will be sent SIGTERM.

问题回答
if [ "a$(pgrep aeolus)" != "a" ] ; 
then 
    pkill gnome-screensaver-command 
    pkill qjackctl
fi

编号:<0>

Another syntax,

if pgrep aeolus
then 
    pkill gnome-screensaver-command 
    pkill qjackctl
fi




相关问题
What does it mean "to write a web service"?

I just asked a question about whether it was possible to write a web-page-checking code and run it from free web server, and one supporter answered and said that it was possible only if I run "a web ...

How can I use exit codes to run shell scripts sequentially?

Since cruise control is full of bugs that have wasted my entire week, I have decided the existing shell scripts I have are simpler and thus better. Here is what I have so far svn update /var/www/...

Dynamically building a command in bash

I am construcing a command in bash dynamically. This works fine: COMMAND="java myclass" ${COMMAND} Now I want to dynamically construct a command that redirectes the output: LOG=">> myfile.log ...

Why does Scala create a ~/tmp directory when I run a script?

When I execute a Scala script from the command line, a directory named "tmp" is created in my home directory. It is always empty, so I simply deleted it without any apparent problem. Of course, when I ...

Ivy, ant and start scripts

I have a project that uses ant to build and ivy for dependencies. I would like to generate the start scripts for my project, with the classpath, based on the dependencies configured in Ivy, ...

热门标签