Question

In: Computer Science

A process creates a child then it gives it 2 seconds to start in order for...

A process creates a child then it gives it 2 seconds to start in order for the child to register a handler for the SIGTSTP signal and stay alert for receiving the signal. Then the parent reads a command without options from the user and sends it to the child using a pipe then sends SIGTSTP signal to the child. The parent waits after that for the child to terminate then exits. The child handles the SIGTSTP signal by reading a command from the pipe and execute it using execlp system call. Write a C program to implement that logic using the signal handling system not sigaction.   

Solutions

Expert Solution

Please go though code and output.

CODE:

#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>


int main()
{
   int fd[2] = {0}; // pipe fd
   pipe(fd); // genrate fd
   int pid =0;

   pid = fork(); // create child process
   if(pid == 0)
   {
       /* In child process */
       char command[32] = {0};
       read(fd[0], command, sizeof(command)); // read from pipe
       execlp(command, command, NULL); // execute command
       exit(0); // exit child
   }
   else
   {
       char command[32] = {0};
      
       printf("Enter command without opeion: \n");
       scanf("%s",command); // get command from user
       write(fd[1], command, strlen(command)); // write in pipe
       sleep(2); // sleep for 2 seconds
       kill(pid, SIGTSTP); // send SIGTSTP signal to child
       wait(0); // wait for child complition
   }

}

OUTPUT:


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...
C programming language The program first creates a child process CP. So, there are two processes:...
C programming language The program first creates a child process CP. So, there are two processes: The parent process does the following: a. compute the summary of all the even number from 1, 2, .. 1000, and output this summary; b. wait for the termination of the child process CP, then terminate; The child process does the following: a. compute the summary of all the odd number from 1, 2, .. 1000, and output this summary; b. terminates;
What are the coordinates of the child after 45 seconds?
For the following exercises, use this scenario: A child enters a carousel that takes one minute to revolve once around. The child enters at the point (0,1), that is, on the due north position. Assume the carousel revolves counter clockwise.What are the coordinates of the child after 45 seconds?
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 that creates a toy scheduler for the child processes in part A....
Write a C program that creates a toy scheduler for the child processes in part A. This program takes as input the number of processes, and all of the PIDs that are being echoed. HINT: Look up redirecting echo output. The program will schedule the ”processes” (note that these are not true processes, this is a toy system. You are effectively only scheduling echo statements). The result of the scheduler will be to echo the PID and current system time...
Given a second order process: 2 AB → A 2 + B 2 with k =...
Given a second order process: 2 AB → A 2 + B 2 with k = 0.0908 M-1min-1; and the initial concentration of AB = 0.941 M, calculate the concentration of A2 after exactly 20 min. Enter the result with 3 sig. figs. exponential notation and no units.
The dataset TrafficFlow gives the delay time in seconds for 24 simulation runs in Dresden, Germany,...
The dataset TrafficFlow gives the delay time in seconds for 24 simulation runs in Dresden, Germany, comparing the current timed traffic light system on each run to a proposed flexible traffic light system in which lights communicate traffic flow information to neighboring lights. On average, public transportation was delayed 105 seconds under the timed system and 44 seconds under the flexible system. Since this is a matched pairs experiment, we are interested in the difference in times between the two...
Half-life equation for first-order reactions: t1/2=0.693k   where t1/2 is the half-life in seconds (s), and k...
Half-life equation for first-order reactions: t1/2=0.693k   where t1/2 is the half-life in seconds (s), and k is the rate constant in inverse seconds (s−1). A. What is the half-life of a first-order reaction with a rate constant of 5.60×10−4 s−1? B. What is the rate constant of a first-order reaction that takes 150 seconds for the reactant concentration to drop to half of its initial value? C. A certain first-order reaction has a rate constant of 7.20×10−3 s−1. How long...
Process Order Costing: Define Process order costing. Trace the flow of costs through a process order...
Process Order Costing: Define Process order costing. Trace the flow of costs through a process order costing system. Explain the concept and calculation of equivalent units of production. Discuss the production report as a decision making tool.
A child weighs 95 lbs and has an order for IV tobramycin. The order is for...
A child weighs 95 lbs and has an order for IV tobramycin. The order is for 3mg/kg/day in three divided doses. How many milligrams of medication should be administered per dose?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT