Results 1 to 2 of 2

Thread: How to Write a program to communicate between two processes using the pipe{ This is urgent so please help me}

  1. #1
    Join Date
    Nov 2011
    Posts
    1

    ohmy How to Write a program to communicate between two processes using the pipe{ This is urgent so please help me}

    I am learning operating system, this is a really big trouble for me, i do not how to write that kind of program above in C++, if anyone know the answer please post complete "code" that write in C++, thank you so much, this is question:
    Write a program to communicate between two processes using the pipe as follows:
    A process read from the file consists of multiple consecutive sequences, each sequence of the operations +, -, *, / and 2 mathematics
    out. For example, the file will save the string like this:
    2 + 3
    1 to 2
    4 * 6
    15 / 3
    Then the first process of the first sequence send(transmit) data for the second process . the second process
    perform calculations and return the resulting string back to the first process to record the
    file as follows:
    2 + 3 = 5
    1-2 = -1
    4 * 6 = 24
    15 / 3 = 5

  2. #2
    Join Date
    Jan 2006
    Posts
    605

    Re: How to Write a program to communicate between two processes using the pipe{ This is urgent so please help me}

    Check the Example code given below:

    writer.c
    Code:
    #include <fcntl.h> 
    #include <sys/stat.h> 
    #include <sys/types.h> 
    #include <unistd.h> 
     
    int main() 
    { 
        int fd; 
        char * myfifo = "/tmp/myfifo"; 
     
        /* create the FIFO (named pipe) */ 
        mkfifo(myfifo, 0666); 
     
        /* write "Hi" to the FIFO */ 
        fd = open(myfifo, O_WRONLY); 
        write(fd, "Hi", sizeof("Hi")); 
        close(fd); 
     
        /* remove the FIFO */ 
        unlink(myfifo); 
     
        return 0; 
    }
    reader.c
    Code:
    #include <fcntl.h> 
    #include <stdio.h> 
    #include <sys/stat.h> 
    #include <unistd.h> 
     
    #define MAX_BUF 1024 
     
    int main() 
    { 
        int fd; 
        char * myfifo = "/tmp/myfifo"; 
        char buf[MAX_BUF]; 
     
        /* open, read, and display the message from the FIFO */ 
        fd = open(myfifo, O_RDONLY); 
        read(fd, buf, MAX_BUF); 
        printf("Received: %s\n", buf); 
        close(fd); 
     
        return 0; 
    }

Similar Threads

  1. Urgent C++ program won't work correctly
    By chinesebarbiedoll in forum Software Development
    Replies: 1
    Last Post: 28-11-2011, 10:07 AM
  2. Need help to write this program in java?
    By frkadeel in forum Software Development
    Replies: 1
    Last Post: 01-12-2010, 03:58 PM
  3. How to write program to get this series: 1248...
    By MKAIF in forum Software Development
    Replies: 6
    Last Post: 19-02-2010, 06:06 PM
  4. When I start a program, nothing happens [URGENT!]
    By Espz in forum Windows Software
    Replies: 3
    Last Post: 14-12-2009, 12:58 AM
  5. How to communicate with USB port with VB.NET program?
    By Chandrakant81 in forum Software Development
    Replies: 4
    Last Post: 18-02-2009, 06:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,870,380.36524 seconds with 17 queries