GithubHelp home page GithubHelp logo

manojvenaram / os-ex.6-implementation-of-inter-process-communication-using-pipe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sujathamohankumar/os-ex.6-implementation-of-inter-process-communication-using-pipe

0.0 0.0 0.0 12 KB

os-ex.6-implementation-of-inter-process-communication-using-pipe's Introduction

OS-EX.6-IMPLEMENTATION-OF-INTER-PROCESS-COMMUNICATION-USING-PIPE

AIM:

To Write C program to illustrate IPC using pipes mechanisms.

ALGORITHM:

Step 1:

Import the os module for process management and communication.

Step 2:

Define a main() function as the program's entry point.

Step 3:

Prompt the user to input a message and encode it as bytes.

Step 4:

Create two pipes, parent_pipe and child_pipe, for communication.

Step 5:

Fork a child process using os.fork().

Step 6:

In the child process, close the parent's pipe end and write the message to the child's pipe end.4

Step 7:

In the child process, close the child's pipe end.

Step 8:

Exit the child process.

Step 9:

In the parent process, close the child's pipe end.

Step 10:

Read the message from the parent's pipe end, decode it, and print it.

PROGRAM:

import os

def main():
    message = input("Enter a message: ").encode()
    parent_pipe, child_pipe = os.pipe()

    child_pid = os.fork()

    if child_pid == 0:
        os.close(parent_pipe)
        os.write(child_pipe, message)
        os.close(child_pipe)
        exit(0)
    else:
        os.close(child_pipe)
        received_message = os.read(parent_pipe, 100)
        os.close(parent_pipe)
        print("Parent received:", received_message.decode())

if __name__ == "__main__":
    main()


OUTPUT:

Result:

This output confirms that the parent process successfully received and printed the message sent by the child process through the pipe, demonstrating inter-process communication using pipes.

os-ex.6-implementation-of-inter-process-communication-using-pipe's People

Contributors

manojvenaram avatar sujathamohankumar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.