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, 04.07.2019 18:10
Carbon dioxide gas expands isotherm a turbine from 1 mpa, 500 k at 200 kpa. assuming the ideal gas model and neglecting the kinetic and potential energies, determine the change in entropy, heat transfer and work for each kilogram of co2.
Answers: 2
question
Engineering, 04.07.2019 18:10
An air compression refrigeration system is to have an air pressure of 100 psia in the brine tank and an allowable air temperature increase of 60°f for standard vapor compression cycle temperatures of 77 f entering the expansion cylinder and 14 f entering the compression cylinder, calculate the coefficient of performance a. 2.5 b 3.3 c. 4.0 d. 5.0
Answers: 3
question
Engineering, 04.07.2019 18:20
Derive the correction factor formula for conical nozzle i=-(1+ cosa) and calculate the nozzle angle correction factor for a nozzle whose divergence hal-fangle is 13 (hint: assume that all the mass flow originates at the apex of the cone.
Answers: 3
question
Engineering, 04.07.2019 18:20
How much power could a wind turbine produce if it had the following specifications? cp = 0.45 -d=1.2kg/m3 d=50m v 5m/s
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, 06.04.2020 18:34
question
English, 06.04.2020 18:35
Questions on the website: 13722363