Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-11-2011
Member
 
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
Reply With Quote
  #2  
Old 11-11-2011
Member
 
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; 
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to Write a program to communicate between two processes using the pipe{ This is urgent so please help me}"
Thread Thread Starter Forum Replies Last Post
Urgent C++ program won't work correctly chinesebarbiedoll Software Development 1 28-11-2011 10:07 AM
Need help to write this program in java? frkadeel Software Development 1 01-12-2010 03:58 PM
How to write program to get this series: 1248... MKAIF Software Development 6 19-02-2010 06:06 PM
When I start a program, nothing happens [URGENT!] Espz Windows Software 3 14-12-2009 12:58 AM
How to communicate with USB port with VB.NET program? Chandrakant81 Software Development 4 18-02-2009 06:52 PM


All times are GMT +5.5. The time now is 04:32 PM.