Answer a question

I'm rushing against the clock for a programming assignment in which I have to run a number of instances of the same program on the same machine at the same time. Currently, I'm starting the instances one at a time, pressing Ctrl+z to pause them, and then doing 'bg %#' to resume execution in the background.

This is extremely tedious and time consuming to do every time I need to test a small change in my application, so I want to write a bash script that will start the multiple instances for me, however I don't know how to do the background switching in a script.

Can anybody please tell me how I can write a simple script that will start a long standing command, pause it, and resume it in the background?

Thanks

Answers

Do you want to just start it in the background? For example:

mycommand &

If you want finer grained job control, you can emulate Ctrl-Z and bg. Control-Z sends SIGTSTP ("tty stop") to the program, which suspends it:

kill -TSTP [processid]

And the bg command just sends it a SIGCONT:

kill -CONT [processid]
Logo

更多推荐