subproccess test

This commit is contained in:
Difrex 2016-08-08 19:06:41 +03:00
parent 4b2000c451
commit cf3a49f801
3 changed files with 45 additions and 0 deletions

10
t/b.sh Executable file
View 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
View 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()

1
t/txt Normal file
View File

@ -0,0 +1 @@
OK