Linux:查找并执行并发xterm

时间:2017-10-30 14:00:08

标签: linux concurrency find execute xterm

我正在尝试为文件夹集合中的每个实例运行客户端和服务器。我试过这个命令:

$ find ./ -name "Makefile" -execdir xterm -title "Server" -e "timeout -s sigint 8s ./server > serverLog.txt" \; -execdir xterm -title "Client" -e "timeout -s sigint 5s ./client > client1Log.txt" \;

但是这会在xterm窗口中运行服务器8秒钟,然​​后关闭该窗口并在xterm窗口中运行客户端5秒钟。我需要客户端和服务器同时为每个发现的Makefile运行。

1 个答案:

答案 0 :(得分:0)

要同时运行两个命令,您必须使用ambersand &,它将首次执行发送到后台并继续下一个。所以你必须执行类似

的操作

cmd1 & cmd2 &cmd1 & cmd2,取决于您的需求。

接下来,您必须在-execdir内部转义ambersand,它接受一个命令。一种方法是

find [params] -execdir sh -c 'cmd1 & cmd2' \;

示例:

find [params] -execdir sh -c 'xterm -e "sleep 8" & xterm -e "sleep 5"' \;