I do have a code that runs the same python script with different arguments at the same time in different Shell windows.
The following code do this, but I need do monitor if any subprocess created have finished its execution, and then stop all other subprocesses running, how can I do this monitoring on Linux?
I have tried to check the PID status, but it changes to 'zombie' after the terminal is opened
import multiprocessing
import subprocess
import psutil
import shlex
if __name__ == '__main__':
arg_list = ["gnome-terminal -- python3 teste.py ./get_data/datasets/training_out.xlsx 140.10.61.1 0 2 102 4 OUTPUT 0 632 MEMORY 0 3885 1 0",
"gnome-terminal -- python3 teste.py ./get_data/datasets/training_out2.xlsx 140.10.61.1 0 2 102 1 OUTPUT 0 272 MEMORY 0 3885 1 1",
"gnome-terminal -- python3 teste.py ./get_data/datasets/training_in.xlsx 140.10.61.1 0 2 102 2 INPUT 0 632 MEMORY 0 3885 1 2",
"gnome-terminal -- python3 teste.py ./get_data/datasets/training_in2.xlsx 140.10.61.1 0 2 102 2 INPUT 0 272 MEMORY 0 3885 1 3",
"gnome-terminal -- python3 teste.py ./get_data/datasets/training_in3.xlsx 140.10.61.1 0 2 102 1 INPUT 0 274 MEMORY 0 3885 1 4"
]
p1 = subprocess.Popen(shlex.split(arg_list[0]))
psProcess1 = psutil.Process(pid=p1.pid)
p2 = subprocess.Popen(shlex.split(arg_list[1]))
psProcess2 = psutil.Process(pid=p2.pid)
p3 = subprocess.Popen(shlex.split(arg_list[2]))
psProcess3 = psutil.Process(pid=p3.pid)
p4 = subprocess.Popen(shlex.split(arg_list[3]))
psProcess4 = psutil.Process(pid=p4.pid)
p5 = subprocess.Popen(shlex.split(arg_list[4]))
psProcess5 = psutil.Process(pid=p5.pid)