-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtutorial_orchestrator.py
More file actions
48 lines (34 loc) · 946 Bytes
/
tutorial_orchestrator.py
File metadata and controls
48 lines (34 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Python program to explain os.pipe() method
# importing os module
import os
# Create a pipe
r, w = os.pipe()
# The returned file descriptor r and w
# can be used for reading and
# writing respectively.
# We will create a child process
# and using these file descriptor
# the parent process will write
# some text and child process will
# read the text written by the parent process
# Create a child process
pid = os.fork()
# pid greater than 0 represents
# the parent process
if pid > 0:
# This is the parent process
# Closes file descriptor r
os.close(r)
# Write some text to file descriptor w
print("Parent process is writing")
text = b"Hello child process"
os.write(w, text)
print("Written text:", text.decode())
else:
# This is the parent process
# Closes file descriptor w
os.close(w)
# Read the text written by parent process
print("\nChild Process is reading")
r = os.fdopen(r)
print("Read text:", r.read())