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 16:10
An electrical motor raises a 50kg load at a construct velencity .calculate the power of the motor, if it takes 40sec to raise the load through a height of 24m(take g =9.8n/g)
Answers: 2
question
Engineering, 04.07.2019 18:10
Aflywheel accelerates for 5 seconds at 2 rad/s2 from a speed of 20 rpm. determine the total number of revolutions of the flywheel during the period of its acceleration. a.5.65 b.8.43 c. 723 d.6.86
Answers: 2
question
Engineering, 04.07.2019 18:10
Consider a large isothermal enclosure that is maintained at a uniform temperature of 2000 k. calculate the emissive power of the radiation that emerges from a small aperture on the enclosure surface. what is the wavelength ? , below which 10% of the emission is concentrated? what is the wavelength ? 2 above which 10% of the emission is concentrated? determine the wavelength at which maximum spectral emissive power occurs. what is the irradiation incident on a small object placed inside the enclosure?
Answers: 2
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
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, 20.04.2020 00:11
question
History, 20.04.2020 00:11
question
Mathematics, 20.04.2020 00:11
question
Chemistry, 20.04.2020 00:11
question
Mathematics, 20.04.2020 00:11