I'm running many programs (all written in fortran). Right now I'm running one program (./first)
but I would like that once it is finished another one starts running (./second)
, and once that other program finishes the next one starts (./third)
and so on. Any idea how can I do that from the terminal? Thanks!
Asked
Active
Viewed 1,786 times
2

Fresher
- 894
- 1
- 7
- 27

user3412058
- 315
- 1
- 4
- 13
2 Answers
7
how about
./first && ./second && ./third
or
./first ; ./second ; ./third
in the first case, the chain is interrupted, if one of the programs fails (exits with exit code != 0). in the second case, the applications keep on running, even if one of them (e.g. ./second) is going to fail.

Pavel
- 7,436
- 2
- 29
- 42
-
1Note the corollary: if you are writing the programs, then you are responsible for making sure that your program correctly returns 0 when it is successful, and non-zero when it fails. – William Pursell May 09 '14 at 13:08
-
But what if the first program is already running? – user3412058 May 09 '14 at 13:45
-
then I guess there's no nice way to do that, other than having a while-true-loop grepping for the PID of the running process and waiting to start the next one. generally, I'd recommend using shell scripts taking care of things like that. – Pavel May 09 '14 at 13:47
-
2It can be done, see my answer. – nobody May 18 '14 at 04:13
2
Assuming you're using bash
or a compatible shell:
- Put
first
in the background by pressing Ctrl-Z (not necessary if it's already backgrounded) - Run
wait && ./second && ./third

nobody
- 19,814
- 17
- 56
- 77