0

In unix/linux, I have a job ./a.out, which is currently running in the background over ssh as

nohup ./a.out &

And I have logged out of the original shell. I want another job ./b.out to start running only after ./a.out finishes. How to do it? The overall effect is equivalent to

./a.out && ./b.out

But I do not want to kill ./a.out.

Edit: clarify that ./a.out is running in the background using nohup. (Thanks to Marc B.)

hbp
  • 235
  • 2
  • 5
  • 17
  • 2
    just type `b.out` in the terminal the `a` job is running on. as long as you don't close that terminal, that input will wait in the input queue for the job to finish and the shell prompt to reappear – Marc B Jun 30 '14 at 18:38
  • @Marc B. Yes, this will work if ./a.out is running in the foreground. But, in my case, ./a.out is currently running in the background. Sorry for not making it clear. Besides, ./b.out might be a complex command. Is there a safer solution to prevent typing errors? – hbp Jun 30 '14 at 18:56
  • background of the same shell? then you could simply `fg` it and do the type-ahead stuff. if it's completely disconnected from the terminal/shell, then you'd need to set up a monitor to keep an eye on its PID and trigger b.out when a.out's pid vanishes. – Marc B Jun 30 '14 at 19:13
  • Sorry, it's a different shell, and ./a.out was run by nohup. – hbp Jun 30 '14 at 19:22
  • `nohup ( a.out; b.out)` will launch a and b in a subshell, one after the other. – wildplasser Jun 30 '14 at 19:33

1 Answers1

1

One approach would be to see what the process ID of a.out is, with top or ps, and have a launcher program that checks once a second to see if that PID is still active. When it isn't, the launcher runs b.out.

Tom Zych
  • 13,329
  • 9
  • 36
  • 53
  • Any specific launcher program to do this? – hbp Jun 30 '14 at 19:08
  • Not that I know of, offhand. It could be written in bash fairly easily, but I don't have time right now. Sending signal 0 to a pid will test if it exists. – Tom Zych Jun 30 '14 at 19:12
  • You can use the answer [here](http://stackoverflow.com/questions/7485776/start-script-after-another-one-already-running-finishes). – jcragun Jun 30 '14 at 19:20
  • @jcragun, thanks a lot! Now should I delete my question (to avoid duplication), or should I somehow link it to the question you mentioned? – hbp Jun 30 '14 at 19:29
  • This is probably sufficient. I guess you could mark this as the answer. – jcragun Jul 01 '14 at 01:46