Question

Using C, write a program that will create two child processes with one child process then...

Using C, write a program that will create two child processes with one child process then using “pipe” to send “i love you” to another child process.

Homework Answers

Answer #1

Program to pass value "I Love you" from one to another childProcess

#include<stdio.h>
#include<unistd.h>

int main() {
int pipefds[2];
int returnstatus;
int pid;
int pid2;
char writemessages[1][20]={"I Love You"};
char readmessage[20];
returnstatus = pipe(pipefds);
if (returnstatus == -1) {
printf("Unable to create pipe\n");
return 1;
}
pid = fork();
pid2 = fork();

// Child process-2
if (pid == 0) {
read(pipefds[0], readmessage, sizeof(readmessage));
printf("Child Process -2 - Reading from pipe – Message 1 is %s\n", readmessage);
} if(pid2 == 0) {
// Child process-1
printf("Child Process- 1 - Writing to pipe - Message 1 is %s\n", writemessages[0]);
write(pipefds[1], writemessages[0], sizeof(writemessages[0]));
}
return 0;
}

Output:

Child Process- 1 - Writing to pipe - Message 1 is I Love You
Child Process -2 - Reading from pipe – Message 1 is I Love You
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
1.Write a c++ program to find Maximum out of two numbers using friend function. Here one...
1.Write a c++ program to find Maximum out of two numbers using friend function. Here one member is of one class and second belongs to another class. 2.Write a c++ program to swap the values of private data members of classes names classOne and classTwo using friend keyword.
The following program calls the fork() system call to create a child process. Suppose that the...
The following program calls the fork() system call to create a child process. Suppose that the actual pids of the parent process and child process are as follows: Parent process: 801 Child process:   802 (as returned by fork) Assume all supporting libraries have been included. => Use the answer text field to write the values of the pids printed at lines 1, 2, 3, and 4 (indicate each line number and the value printed). int main() {      pid_t pid,...
Write a C++ program that processes orders for our company Widgets and More. Your program will...
Write a C++ program that processes orders for our company Widgets and More. Your program will read the product code and quantity for all the products in an order from a file, order.txt. You will be given a sample order.txt with the starter code. There are two items on each line of the file the first is a letter that represents the product and the second is an integer representing the number bought. Based on the product and quantity, you...
Program Assignment 1: Process Management Objective: This program assignment is given to the Operating Systems course...
Program Assignment 1: Process Management Objective: This program assignment is given to the Operating Systems course to allow the students to figure out how a single process (parent process) creates a child process and how they work on Unix/Linux(/Mac OS X/Windows) environment. Additionally, student should combine the code for describing inter-process communication into this assignment. Both parent and child processes interact with each other through shared memory-based communication scheme or message passing scheme. Environment: Unix/Linux environment (VM Linux or Triton...
Hello. for one of my assignment, I need to create any program using the C language...
Hello. for one of my assignment, I need to create any program using the C language and that must contain the following: - Error Checking - Use of Functions - Menu system - Array Processing It can be about anything, nothing specified but must contain the features mentioned above Thank you
Write the following using C language for program in Arduino: Write a program that turns on...
Write the following using C language for program in Arduino: Write a program that turns on first LED for one second, then first LED off, wait for one second, then second LED turns on for one second, then goes off, wait for one second, keep going for third and fourth LEDs, and the program repeats until power is cut or new program uploaded.
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
Using python, write the program below. Program Specifications: You are to write the source code and...
Using python, write the program below. Program Specifications: You are to write the source code and design tool for the following specification: A student enters an assignment score (as a floating-point value). The assignment score must be between 0 and 100. The program will enforce the domain of an assignment score. Once the score has been validated, the program will display the score followed by the appropriate letter grade (assume a 10-point grading scale). The score will be displayed as...
explain why one firm would try to improve their processes using process flow chart analysis while...
explain why one firm would try to improve their processes using process flow chart analysis while another use business process reengineering
In this project, you will write C code to solve the Collatz conjecture using ordinary pipes...
In this project, you will write C code to solve the Collatz conjecture using ordinary pipes to share data between parent and child processes Here are the rules for your program: The starting number will be entered on the command line. Be sure to check that it is positive. The parent will handle the command line and pass the integer to the child. The child will do the calculation and pass the sequence generated back to the parent. The parent...