From cf3a49f801c70d25cfd68f5392505a2eb7a196b2 Mon Sep 17 00:00:00 2001 From: Difrex Date: Mon, 8 Aug 2016 19:06:41 +0300 Subject: [PATCH] subproccess test --- t/b.sh | 10 ++++++++++ t/f.py | 34 ++++++++++++++++++++++++++++++++++ t/txt | 1 + 3 files changed, 45 insertions(+) create mode 100755 t/b.sh create mode 100755 t/f.py create mode 100644 t/txt diff --git a/t/b.sh b/t/b.sh new file mode 100755 index 0000000..ce193e3 --- /dev/null +++ b/t/b.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +echo $$ > /var/tmp/surok.spid + +while true; do + cat txt + sleep 2 +done diff --git a/t/f.py b/t/f.py new file mode 100755 index 0000000..a5be042 --- /dev/null +++ b/t/f.py @@ -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() diff --git a/t/txt b/t/txt new file mode 100644 index 0000000..d86bac9 --- /dev/null +++ b/t/txt @@ -0,0 +1 @@ +OK