Question

In: Computer Science

Using pipes for inter-process communications, write a C program to produce a parent/child relationship in which...

Using pipes for inter-process communications, write a C program to produce a parent/child relationship in which the parent process repeatedly counts and displays on the screen the number of characters for any user password the child process inputs to the pipe. The communications should cease once the string “Done” is inputted.

Solutions

Expert Solution

This is a C program to produce a parent/child relationship in which

the parent process repeatedly counts and displays on the screen the number of characters for any user password the child process inputs to the pipe.

The communications will cease once the string “Done” is inputted.

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

int main()
 {
   int pipefds[2];
   int returnstatus;
   int pid;
   char password[100];
   returnstatus = pipe(pipefds);
   if (returnstatus == -1) {
      printf("Unable to create pipe\n");
      return 1;
   }
   pid = fork();
   while(1)
   {   printf("enter the password");
       scanf("%s" , password);
       if(password="Done")
       { return 0;}
       else
      {    // child process
           if (pid == 0) {
             printf("child Process - Writing to pipe - password is %s\n", password);         
             write(pipefds[1], password, sizeof(password));}
           else { //parent process
             read(pipefds[0], readmessage, sizeof(readmessage)); 
             printf("Child Process - Reading from pipe – length of password is %d\n", strlen(readmessage));}
  }

return 0;

}


Related Solutions

Write a “C” program(Linux) that creates a pipe and forks a child process. The parent then...
Write a “C” program(Linux) that creates a pipe and forks a child process. The parent then sends the following message on his side of the pipe “I am your daddy! and my name is <pid-of the-parent-process>\n”, the child receives this message and prints it to its stdout verbatim. The parent then blocks reading on the pipe from the child. The child writes back to its parent through its side ofthe pipe stating “Daddy, my name is <pid-of-the-child>”. The parent then...
You will write a C program to fork a child process. The child process will print...
You will write a C program to fork a child process. The child process will print the current time/date. The parent will wait for the child to complete. Here is how you can programmatically call the Linux date command from a C program. execlp("/bin/date","date",NULL); Your C file should be named myfork.c The binary will be named myfork.
Write a C program which fork the process and have the child execute a process.You have...
Write a C program which fork the process and have the child execute a process.You have to implement void forkexec(char** argv).This takes in an array of strings representing arguments.The first argument is the filename of an executable (which will be given as a "./a").The remaining terms would be arguments for said executable.The array is null terminated and you need to fork your process.The child needs to call exec/execvp to execute the specified file with the specified arguments. Also have the...
Client AND server using names pipes (mkfifo) in C/C++ Write and client program that will talk...
Client AND server using names pipes (mkfifo) in C/C++ Write and client program that will talk to a server program in two separate terminals. Write the server program that can handle multiple clients (so threads will be needed) and with fork() and exec()
Write a program to demonstrate the implementation of Inter Process Communication (IPC) using shared memory. Single...
Write a program to demonstrate the implementation of Inter Process Communication (IPC) using shared memory. Single line text.
how to run child process and parent process in parallel/at the same time in python using...
how to run child process and parent process in parallel/at the same time in python using os
please use c write a program that utilizes pipes for Interprocess Communication (IPC). The program will...
please use c write a program that utilizes pipes for Interprocess Communication (IPC). The program will create a pipe(s) to allow the parent and child to communicate. The parent process will generate a random number based on the pid of the child process created. The parent will send this random number to the child and wait for a response (Received) from the child. After receiving a response from the child, the parent will send another message to the child telling...
Write a program in C or C++ that spawns three child processes. The first child sends...
Write a program in C or C++ that spawns three child processes. The first child sends a signal to the parent (you'll need the parent's pid!), which the parent shall catch. The second child waits for 10 seconds and then terminates. Once the parent detects that both of these has happened, it should signal the third child to terminate.
C++ Code You will write a program to process the lines in a text file using...
C++ Code You will write a program to process the lines in a text file using a linked list and shared pointers. You will create a class “Node” with the following private data attributes: • Line – line from a file (string) • Next (shared pointer to a Node) Put your class definition in a header file and the implementation of the methods in a .cpp file. The header file will be included in your project. If you follow the...
Pick a pair of concrete classes in the JDK in a parent-child relationship and discuss a...
Pick a pair of concrete classes in the JDK in a parent-child relationship and discuss a few polymorphic and/or overloaded methods. Do not use Object as the parent class - it is too trivial to address the issues to be addressed here, and in any case, Object is the final parent of all classes in Java.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT