0

The title is ambiguous, so I add example.

I usually run python files by bash file.

Bash file name : train.sh

python train1.py 

python train2.py

Then I run nohup bash train.sh > out.out &.

So, train1.py and train2.py are run sequentially.
And when I found mistakes, I stopped using check PID using nvidia-smi and kill -9 PID .

However, of cousre, only train1.py stopped and then start train2.py.

What I want to do is.

I want stop both train1.py and train2.py even if current running file is train1.py.

In other words, I want stop running python file and files to be ran.

And I have one more question.

How can I get PIDs for running bash files?
(Assuming that 2 bash files like above example are running, I want to get PIDs for each.)

Thank You

Jake
  • 65
  • 4

1 Answers1

0

To get the PID of process (A program "python script" loaded into memory and executing is called Process)

ps -ef | awk '$8=="name_of_process" {print $2}'

To check that python a.py completed successfully as a required condition for running python b.py, you can do:

#!/usr/bin/env bash
python a.py && python b.py

To run both program background in same time

#!/usr/bin/env bash
python a.py &
python b.py &
Joseph
  • 136
  • 1
  • 2
  • 8