Python Forum
How to run same process simultaneously
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to run same process simultaneously
#1
I have a jar and I want to make a python script for linux that checks if the jar is opened in the linux task manager and if its not to open it 5 times. From time to time it should check the 5 processes and when all 5 end open them again.

This is the code that I`ve written in python:

import psutil

import subprocess

process_name = "/root/Linux/ArhivareProd.jar"

for proc in psutil.process_iter():

process = psutil.Process(proc.pid)

pname = process.name()

if pname != process_name:

subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar'])

subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar'])

subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar'])

subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar'])

subprocess.call(['java','-jar','/root/Linux/ArhivareProd.jar'])


else:

print("Minim un proces ArhivareProd.jar deja ruleaza !")
When I run it it only opens one jar process

How can I modify the script so it opens up 5 processes ?

Thanks
Reply
#2
Try
procs = []
for i in range(5):
    p = subprocess.Popen(['java','-jar','/root/Linux/ArhivareProd.jar'])
    procs.append(p)
from p in procs:
    p.wait()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to sharing object between multiple process from main process using Pipe Subrata 1 1,049 Sep-03-2019, 09:49 PM
Last Post: woooee
  Control 2 stepper motor simultaneously jihene 2 1,024 May-08-2019, 05:27 PM
Last Post: DeaD_EyE
  Moving with objects simultaneously kom2 1 650 Apr-20-2019, 07:12 PM
Last Post: SheeppOSU
  using subpocess for both reading and writing simultaneously dauriac 11 3,643 May-30-2018, 10:09 PM
Last Post: killerrex
  controlling multiple server simultaneously. caligola 3 1,236 May-11-2018, 05:44 PM
Last Post: wavic
  How to define two functions run simultaneously within a function? Alberto 4 1,615 Feb-06-2018, 10:08 PM
Last Post: Alberto
  Modifying / extracting multiple list items simultaneously using variable from range ehammarlund 4 1,629 Dec-06-2017, 08:15 PM
Last Post: ehammarlund

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020