পাইপ তৈরি করা (Inter-Process Communication)
os.pipe() একটি পাইপ তৈরি করে এবং রিড/রাইটের জন্য ফাইল ডেসক্রিপ্টর জোড়া (r, w) রিটার্ন করে।
উদাহরণ: প্যারেন্ট-চাইল্ড কমিউনিকেশন
import os, sys
print("The child will write text to a pipe and ")
print("the parent will read the text written by child...")
r, w = os.pipe()
processid = os.fork()
if processid: # প্যারেন্ট প্রসেস
os.close(w)
r = os.fdopen(r)
print("Parent reading")
str = r.read()
print("text =", str)
sys.exit(0)
else: # চাইল্ড প্রসেস
os.close(r)
w = os.fdopen(w, 'w')
print("Child writing")
w.write("Text written by child...")
w.close()
print("Child closing")
sys.exit(0)
আউটপুট
Parent reading Child writing Child closing text = Text written by child...
নোট: os.fork() শুধু ইউনিক্সে কাজ করে। উইন্ডোজে multiprocessing মডিউল ব্যবহার করুন।