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
Write a C program that creates (or spawns) a child process to execute the Unix's command...
Write a C program that creates (or spawns) a child process to execute the Unix's command (echo) with a string as the command-line argument; while the program itself (the parent process) will execute another Unix command less with a filename as the command-line argument. If you aren't sure how the echo and less commands are meant to behave, experiment with them by running them directly from the command line first.
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...
Part 1 Write a program where a child is created to execute command that tells you...
Part 1 Write a program where a child is created to execute command that tells you the date and time in Unix. Use ​execl(...)​. Note: you need to specify the full path of the file name that gives you date and time information. Announce the successful forking of child process by displaying its PID. Part 2 Write a program where a child is created to execute a command that shows all files (including hidden files) in a directory with information...
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...
program in C with one parent thread and two child threads. Both child threads work on...
program in C with one parent thread and two child threads. Both child threads work on the single global variable sum. Each of them implements one for loop, and the for loop is designed to complete 10000 iterations. • One child thread add 1 to sum in each iteration of the for loop. starting with 0 and finishing with 10000. • The other child thread, decrements on 1 the value of sum in each iteration of the for loop.
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 a C program that outputs a formatted header line and creates 10 children processes each...
Write a C program that outputs a formatted header line and creates 10 children processes each of which displays a line of the output as shown below. Notice the values of Child no and x, they have to be the same as shown here while the processes PIDs values are based on the what your system assigns to these processes. Child    PID        PPID      X 0           13654    13653    5 1           13655    13653    10 2           13656    13653    15 3           13657    13653    20...
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.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT