subproccess test
This commit is contained in:
parent
4b2000c451
commit
cf3a49f801
10
t/b.sh
Executable file
10
t/b.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
echo $$ > /var/tmp/surok.spid
|
||||
|
||||
while true; do
|
||||
cat txt
|
||||
sleep 2
|
||||
done
|
34
t/f.py
Executable file
34
t/f.py
Executable file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from time import sleep
|
||||
import sys
|
||||
|
||||
|
||||
def child():
|
||||
bashCommand = "./b.sh"
|
||||
process = subprocess.Popen(bashCommand, stdout=sys.stdout)
|
||||
# output = process.communicate()
|
||||
|
||||
return process
|
||||
|
||||
|
||||
def parent():
|
||||
newpid = os.fork()
|
||||
if newpid == 0:
|
||||
child()
|
||||
else:
|
||||
pids = (os.getpid(), newpid)
|
||||
print("parent: %d, child: %d\n" % pids)
|
||||
|
||||
c = 0
|
||||
while c < 5:
|
||||
sleep(2)
|
||||
p = open('/var/tmp/surok.spid')
|
||||
cpid = p.read()
|
||||
p.close()
|
||||
print(cpid, c)
|
||||
c = c + 1
|
||||
|
||||
parent()
|
Loading…
Reference in New Issue
Block a user