Search code examples
linuxconcurrencyfindexecutexterm

Linux: Find and Execute Concurrent xterm


I am trying to run a client and server for each instance in a collection of folders. I tried this command:

$ 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" \;

But this ran the server in an xterm window for 8 seconds and then closed that window and ran the client in an xterm window for 5 seconds. I need the client and server to run at the same time for each Makefile found.


Solution

  • To run two commands concurrently you have to use the ambersand &, which will send first execution to background and continues with the next one. So you have to exec something like

    cmd1 & cmd2 & or cmd1 & cmd2 , it depends on what you want.

    Next you have to escape ambersand while inside -execdir, which accepts one command. One way to do this is

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

    example:

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