কম্পিউটার টিউটোরিয়াল

পাইথনে os.pipe() ফাংশনের কাজ কী?


পাইপ তৈরি করা (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 মডিউল ব্যবহার করুন।

  1. পাইথনে raw_input() ফাংশন কী কাজ করে?

  2. পাইথনে <code>reload()</code> ফাংশন কী করে?

  3. পাইথনে নেমস্পেস কী?

  4. পাইথনে স্ট্রিং-এ % অপারেটর কী করে