subject
Engineering, 08.05.2021 03:30 talannajanis

Unix shells support the notion of job control, which allows users to move jobs back and forth between background and foreground, and to change the process state (running, stopped, or terminated) of the processes in a job. Typing ctrl-c causes a SIGINT signal to be delivered to each process in the foreground job. The default action for SIGINT is to terminate each process. Similarly, typing ctrl-z causes a SIGTSTP signal to be delivered to each process in the foreground job. The default action for SIGTSTP is to place a process in the stopped state, where it remains until it is awakened by the receipt of a SIGCONT signal. Unix shells also provide various built-in commands that support job control. For example: jobs: List the running and stopped background jobs.
bg : Change a stopped background job to a running background job.
fg : Change a stopped or running background job to a running in the foreground.
kill : Terminate a job.
Implement these commands in your smallsh. c program. You have to use your own signal handler routines for these purposes along with a simple data structure for maintaining the jobs and processes in each job. You may use process group concept in this implementation for maintaining processes in each job (job may be interpreted as a process group). If your program use fork() system calls, multiple children processes will be created which belong to the same job as your original process which spawned the children processes.
Example
Suppose that you have a program that includes 1 fork system call. Let’s name that executable file as "prog1". Also, assume that both the parent and the child process will sleep 60 seconds and exit. Suppose that you execute the following sequence of commands in less than 60 seconds.

Command> prog1&

Command> prog1&

Command> prog1



Then there are 3 jobs created where each job contains 2 processes. One job is running in foreground, and two jobs are running in background.



#include "smallsh. h"
int runcommand(Char **cline, int where)
{
pid_t pid;
int status;

switch(pid=fork())
{
case -1:
perror("smallsh");
return(-1);
case 0:
execvp(*cline, cline);
perror(*cline)
exit(1);
}
if(where==BACKGROUND)
{
printf("process id is %d\n",pid);
return 0;
}
if(waitpid(pid,&status,0)==-1)< br /> return -1;
else
return status;
}

ansver
Answers: 3

Another question on Engineering

question
Engineering, 03.07.2019 23:20
Two technicians are discussing the intake air temperature (iat) sensor. technician a says that the computer uses the iat sensor as a backup to the engine coolant temperature (ect) sensor. technician b says that the powertrain control module (pcm) will subtract the calculated amount of fuel if the air measures hot. who is correct
Answers: 3
question
Engineering, 04.07.2019 18:10
Hydraulic fluid with a sg. of 0.78 is flowing through a 1.5 in. i.d. pipe at 58 gal/min. the fluid has an absolute viscosity of 11.8 x 105 lbf-sec/ft2. is the flow laminar, turbulent or within the critical range? give both a numerical reynolds number and a term answer.
Answers: 3
question
Engineering, 04.07.2019 18:10
The flow rate of air through a through a pipe is 0.02 m5/s. a pitot static tube is placed in the flow. the radius of the pitot static tube is 1 mm. assuming the flow to be steady and the air to be at 300k, calculate the difference in total and static pressure if the diameter of the pipe is: (a) d 0.1 m d 0.05 m (c) d 0.01 m
Answers: 2
question
Engineering, 04.07.2019 18:20
Avolume of 2.65 m3 of air in a rigid, insulated container fitted with a paddle wheel is initially at 264 k, 5.6 bar. the air receives 432 kj by work from the paddle wheel. assuming the ideal gas model with cv = 0.71 kj/kg • k, determine for the air the amount of entropy produced, in kj/k
Answers: 2
You know the right answer?
Unix shells support the notion of job control, which allows users to move jobs back and forth betwee...
Questions
question
Mathematics, 31.08.2020 01:01
question
Mathematics, 31.08.2020 01:01
question
Mathematics, 31.08.2020 01:01
Questions on the website: 13722367