Python: changing a process name with setproctitle

I have a python script that runs a number of C ++ programs, a command line parameter is passed to each program, as shown below

process_path "~/test/"
process_name "test"
num_process = 10

for p in range(1, num_processes, 1):
    subprocess.Popen([process_path + process_name, str(p)], shell = False)

Is it possible to set setproctitle to rename each of these processes so that I can include the command line parameter as part of the process name, if so, how would you do it?

+3
source share
3 answers

If you pass kwarg executableto subprocess.Popen, you can use the first argument in the argument list:

subprocess.Popen(['some string you choose', str(p)],
                 executable=process_path+process_name, shell=False)

docs say: "On Unix, it becomes the display name for the executable in utilities such as ps."

+1
source

setproctitle "" , , - - - , .

, setproctitle , , , , , Linux , .

Linux prctl(), , prctl (PR_SET_NAME, "my_new_name" );, . , , setproctitle - .

++, prctl.

Linux, , , , prctl.

+1

Windows: , (, calc.exe). ( , ) (CUI), start ( , start/? ):

for p in range(1, num_processes, 1):
    subprocess.Popen(['start', str(p), process_path + process_name, str(p)], shell = False)
    #                            ^ this is the title

.

0

Source: https://habr.com/ru/post/1761113/


All Articles