Python: Why does subprocess () start 2 processes in Ubuntu and 1 in OpenSUSE?

I wrote a small Python GUI that allows users to play Internet radio channels. The program uses the Python () subprocess to initialize mplayer to tune to the pipe, for example:

runn = "mplayer http://77.111.88.131:8010"
p = subprocess.Popen(runn, shell=True)
pid = int(p.pid)
wait = os.waitpid(p.pid, 1)

Then it saves p.pid, and when the user wants to stop listening, the following code is used:

os.kill(p.pid, 9)

This works fine in OpenSUSE, but not in Ubuntu. Ubuntu seems to actually be launching two separate processes. Terminal output:

Opensuse 11.3:

$ pgrep mplayer
22845

Ubuntu 10.04:

$ pgrep mplayer
22846
22847

This also applies when starting other programs. Does anyone know why? I really want this application to run on all distributions, so any help is greatly appreciated.

+3
3

:

p = subprocess.Popen(runn.split(), shell=False)

, , ...

shell=True, sh -c "your string". sh , ( ). . sh -c "your string", - , your string.

sh , exec . , sh , sh . sh -c , sh , .

-, , - subprocess.Popen shell=True. , , sh -c.

+4

, :

pstree / .

ps -awux, .

, shell=True (, /bin/bash), mplayer. . ?

mplayer? python?

+1

subprocess.Popen Popen . , , os.kill...

Does the same thing happen if you use the Popen object p.terminate () or p.kill () methods?

0
source

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


All Articles