1

I set up something so that I'd open up 3 shells and run the programs one by one:

cd foo/bar
./foo.sh
cd foo/bar
node bar.js
cd foo/bar
ruby foobar.rb

However, since it is time consuming, so I wrote a shell script to do it:

cd foo/bar

./foo.sh &
node bar.js &

ruby foobar.rb

However, when I press CTRL-C to stop this script, the other 2 programs are still running. If I type

jobs

it won't show the background processes (probably belongs to the script) -- if it did, I could have used fg to bring them to the foreground and press CTRL-C on them one by one, so I have to do

ps ax | grep foo
ps ax | grep bar

to find the process ids and then kill the processes.

Is there a better way to automate the process to open up 3 shells and run 3 programs so that they are like how I open up 3 shells and run them? I don't care about the STDOUT output, so if one shell window is divided into 3 parts, that's ok.

Can tmux, emacs, or any other tool achieve this goal? (I am not familiar with tmux or emacs enough to know if it is possible).

1

1 Answer 1

2

Not an answer to your main question (I'm a screen user myself, never felt the need to move to tmux), but a comment on:

However, since it is time consuming, so I wrote a shell script to do:

cd foo/bar

./foo.sh &
node bar.js &

ruby foobar.rb

However, when I press CTRL-C to stop this script, the other 2 programs are still running

When you do cmd & in a non-interactive shell, the shell sets the disposition of the SIGINT and SIGQUIT signals to "ignore" for the process running cmd as required by POSIX which explains why Ctrl+c doesn't kill them.

However, several shells, including zsh, bash, mksh and yash (but not dash, ksh93, bosh where that trap command is ignored) allow you to restore the default disposition for those signals with:

#! /bin/zsh -
cd foo/bar || exit
(trap - INT QUIT; ./foo.sh) &
(trap - INT QUIT; node bar.js) &
ruby foobar.rb
wait

Then, Ctrl+c will also kill those commands started asynchronously.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .