

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to communicate between parent and child process using the pipe.
Using fork is the easiest way to create child process.fork () is part of the os standard Python library.
Here, we solve this task by using of pipe(). For passing information from one process to another pipe() is used. For two way communication two pipes can be use, one for each direction because pipe() is unidirectional.
Algorithm
Step 1: file descriptors r, w for reading and writing. Step 2: Create a process using the fork. Step 3: if process id is 0 then create a child process. Step 4: else create parent process.
Example Code
import os def parentchild(cwrites): r, w = os.pipe() pid = os.fork() if pid: os.close(w) r = os.fdopen(r) print ("Parent is reading") str = r.read() print( "Parent reads =", str) else: os.close(r) w = os.fdopen (w, 'w') print ("Child is writing") w.write(cwrites) print("Child writes = ",cwrites) w.close() # Driver code cwrites = "Python Program" parentchild(cwrites)
Output
Child is writing Child writes = Python Program Parent is reading Parent reads = Python Program
- Related Questions & Answers
- Process vs Parent Process vs Child Process
- Calculation in parent and child process using fork() in C++
- Creating child process using fork() in Python
- How to get the child element of a parent using JavaScript?
- How to create a child window and communicate with parents in Tkinter?
- Difference Between Program and Process
- jQuery parent > child Selector
- How to communicate between Activity and Service in Android using Kotlin?
- Run Python script from Node.js using child process spawn() method?
- C program to demonstrate fork() and pipe()
- How to get the parent process of the Process API in Java 9?
- What is the difference between process and program?
- What are Java parent and child classes in Java?
- How to remove all child nodes from a parent using jQuery?
- How to remove all child nodes from a parent node using jQuery?
Advertisements