本文整理汇总了C++中deletejob函数的典型用法代码示例。如果您正苦于以下问题:C++ deletejob函数的具体用法?C++ deletejob怎么用?C++ deletejob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了deletejob函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU signal. The
* handler reaps all available zombie children, but doesn't wait
* for any other currently running children to terminate.
*/
void
sigchld_handler(int sig)
{
pid_t pid;
int status;
while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0)
{
struct job_t *job = getjobpid(job_list, pid);
if (WIFSIGNALED(status))
{
printf("Job [%d] (%d) terminated by signal %d\n", job->jid, pid, WTERMSIG(status));
deletejob(job_list, pid);
}
else if (WIFSTOPPED(status))
{
printf("Job [%d] (%d) stopped by signal %d\n", job->jid, pid, WSTOPSIG(status));
job->state = ST;
}
else
{
deletejob(job_list, pid);
}
}
return;
}
开发者ID:ZHAOTING,项目名称:ICS-lab,代码行数:33,代码来源:tsh.c
示例2: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int olderrno = errno;
sigset_t mask_all, prev_all;
pid_t pid;
int status;
Sigfillset(&mask_all);
while ((pid = waitpid(-1, &status, WNOHANG|WUNTRACED)) > 0) {
Sigprocmask(SIG_BLOCK, &mask_all, &prev_all); /* Block Signals*/
if (WIFEXITED(status)) { /* Exit normally */
deletejob(jobs, pid);
}
if (WIFSIGNALED(status)) { /* C-c SIGINT */
printf("Job [%d] (%d) terminated by signal 2\n", pid2jid(pid), pid);
deletejob(jobs, pid); /* Note: printf first, then deletejob */
}
if (WIFSTOPPED(status)) { /* C-z SIGTSTP */
printf("Job [%d] (%d) stopped by signal 20\n", pid2jid(pid), pid);
getjobpid(jobs, pid)->state = ST;
}
Sigprocmask(SIG_SETMASK, &prev_all, NULL); /* Unblock Signals*/
}
errno = olderrno;
return;
}
开发者ID:fffxj,项目名称:csapp,代码行数:34,代码来源:tsh.c
示例3: waitfg
/*
* waitfg - Block until process pid is no longer the foreground process
*/
void waitfg(pid_t pid)
{
int status;
if ((pid = waitpid(pid, &status, WUNTRACED)) < 0)
{
perror("waitfg error:");
exit(0);
}
else
{
if (WIFSTOPPED(status))
{
int jid = pid2jid(pid);
printf("Job [%d] %d stopped by signal: Stopped\n",jid,(int)pid);
}
else if (WIFEXITED(status))
{
deletejob(jobs,pid);
}
else if (WIFSIGNALED(status))
{
printf("Job %d terminated by signal: Interrupt\n",(int)pid);
deletejob(jobs,pid);
}
}
return;
}
开发者ID:THTBSE,项目名称:Unix,代码行数:30,代码来源:shell.cpp
示例4: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
struct job_t *job;
int status;
pid_t pid;
while((pid=waitpid(-1,&status,WNOHANG|WUNTRACED))>0) //returns pid of child if OK,0 or -1 on error
{
job = getjobpid(jobs,pid);
if(WIFEXITED(status))
{
deletejob(jobs,pid);//deleting jobs if exited normally
}
if(WIFSIGNALED(status))
{
printf("Job [%d] (%d) terminated by signal %d\n",job->jid,pid,WTERMSIG(status));
deletejob(jobs,pid); //deleting jobs terminated with signals
}
if(WIFSTOPPED(status))
{
printf("Job [%d] (%d) stopped by signal %d\n",job->jid,pid,WSTOPSIG(status));
job->state = ST; //changing the state of stopped jobs to ST
}
}
return;
}
开发者ID:jasm123,项目名称:Tiny-shell,代码行数:32,代码来源:tsh.c
示例5: fg_waitpid
void fg_waitpid(pid_t pid) {
int status;
pid_t r_pid;
struct job *p;
if ((r_pid = waitpid(pid, &status, 0)) > 0) {
printf("fg_waitpid in, forepid=%d, r_pid=%d\n", forepid, r_pid);
forepid = 0;
if (WIFEXITED(status)) {
deletejob(r_pid);
fprintf(stderr, "job %d terminated normally with exit status=%d\n",
r_pid, WEXITSTATUS(status));
}
else if (WIFSTOPPED(status)) {
p = selectjob(r_pid);
p->state = 0;
fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n",
p->jid, r_pid);
}
else if (WIFSIGNALED(status)) {
deletejob(r_pid);
fprintf(stderr, "job %d terminated by ", r_pid);
psignal(WTERMSIG(status), "signal");
}
}
else if (errno != ECHILD)
fprintf(stderr, "waitpid error: %s\n",
strerror(errno));
printf("foreground reaped pid=%d, ready to return\n", r_pid);
return;
}
开发者ID:Logic2soul,项目名称:csapp2E,代码行数:31,代码来源:myshell_bug2.c
示例6: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int pid = 1;
int status ;
while( pid >0 ){
pid=waitpid(-1,&status,WNOHANG|WUNTRACED);
if( pid > 0){
if(WIFEXITED(status)){ // child exited normally
//printf( "killed job [%d] , PID: %d with SIGINT \n", getjobpid(jobs, pid)->jid, getjobpid(jobs, pid)->pid );
deletejob(jobs,pid);
}
//child caught signal!!
if(WIFSIGNALED(status)){
printf( "killed job [%d] , PID: %d with SIGINT \n", getjobpid(jobs, pid)->jid, getjobpid(jobs, pid)->pid );
deletejob(jobs,pid); // cntrl c so delete the job after kill is called
}
if(WIFSTOPPED(status)){
printf( "stopped job [%d] , PID: %d with SIGTSTP\n", getjobpid(jobs, pid)->jid, getjobpid(jobs, pid)->pid );
getjobpid(jobs, pid)->state=ST; // cntrl z so set the state to stop after kill is called
}
}
}
}
开发者ID:ryosaito999,项目名称:cs160,代码行数:34,代码来源:tsh.c
示例7: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
// Save current errno value
int tempErrNo = errno;
int status = 0;
pid_t pid;
if ((pid = waitpid(-1, &status, WNOHANG|WUNTRACED)) > 0) {
if (WIFEXITED(status)) {
deletejob(jobs, pid);
}
else if (WIFSIGNALED(status)) {
// Get the terminated job
struct job_t* myJob = getjobpid(jobs, pid);
// Print info on therminated job
safe_printf("Job [%d] (%d) terminated by signal %d\n", myJob->jid, myJob->pid, WTERMSIG(status));
deletejob(jobs, pid);
}
else if (WIFSTOPPED(status)) {
// Get the stopped job
struct job_t* myJob = getjobpid(jobs, pid);
// Change the state to stopped
myJob->state = ST;
// Print info on stopped job
safe_printf("Job [%d] (%d) stopped by signal %d\n", myJob->jid, myJob->pid, WSTOPSIG(status));
}
}
else {
if (errno != 0) {
unix_error("Waitpid error");
}
}
// Restore errno value
errno = tempErrNo;
return;
}
开发者ID:athorhallsson,项目名称:tinyshell,代码行数:42,代码来源:tsh.c
示例8: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
pid_t pid;
int status;
while((pid=waitpid(-1,&status,WNOHANG|WUNTRACED))>0)
{
if(WIFSIGNALED(status))
{
struct job_t* tempjob;
if((tempjob=getjobpid(jobs,pid))!=NULL)
{
printf("Job [%d] (%d) terminated by signal %d\n",tempjob->jid,tempjob->pid,WTERMSIG(status));
deletejob(jobs,pid);
}
continue;
}
if(WIFSTOPPED(status))
{
struct job_t* tempjob;
if((tempjob=getjobpid(jobs,pid))!=NULL)
{
if(tempjob->state!=ST)
{
printf("Job [%d] (%d) stopped by signal %d\n",tempjob->jid,tempjob->pid,SIGTSTP);
tempjob->state=ST;
}
}
continue;
}
deletejob(jobs,pid);
}
return;
}
开发者ID:abucraft,项目名称:ics-Lab,代码行数:41,代码来源:tsh.c
示例9: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
struct job_t *jd;
pid_t pid;
int status = -1;
//returns 0 if working correctly, and will return -1 if it errors out
while((pid = waitpid(-1, &status, WNOHANG|WUNTRACED)) > 0){
jd = getjobpid(jobs, pid);
if(WIFEXITED(status)){
deletejob(jobs, pid);
}
if(WIFSIGNALED(status)){
printf("[%d] (%d) terminated by signal 2\n",jd->jid, pid);
deletejob(jobs, pid);
}
if(WIFSTOPPED(status)){
printf("[%d] (%d) terminated by signal 20\n",jd->jid, pid);
jd->state = ST;
}
}
return;
}
开发者ID:Jonathansw,项目名称:Random-Code,代码行数:36,代码来源:tsh.c
示例10: sigchld_handler
void sigchld_handler(int sig) {
pid_t pid;
int status;
struct job *p;
if ((pid = waitpid(-1, &status, WUNTRACED)) > 0) {
if (pid == forepid)
forepid = 0;
if (WIFEXITED(status))
deletejob(pid);
else if (WIFSTOPPED(status)) {
p = selectjob(pid);
p->state = 0;
fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n",
p->jid, pid);
}
else if (WIFSIGNALED(status)) {
deletejob(pid);
fprintf(stderr, "job %d terminated by ", pid);
psignal(WTERMSIG(status), "signal");
}
}
else if (errno != ECHILD)
fprintf(stderr, "\nwaitpid error: %s\n", strerror(errno));
return;
}
开发者ID:Logic2soul,项目名称:csapp2E,代码行数:25,代码来源:myshell_release.c
示例11: fg_waitpid
void fg_waitpid(pid_t pid) {
int status;
pid_t r_pid = 0;
struct job *p = NULL;
if ((r_pid = waitpid(pid, &status, 0)) > 0) {
forepid = 0;
if (WIFEXITED(status))
deletejob(r_pid);
else if (WIFSTOPPED(status)) {
p = selectjob(r_pid);
p->state = 0;
fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n",
p->jid, r_pid);
}
else if (WIFSIGNALED(status)) {
deletejob(r_pid);
fprintf(stderr, "job %d terminated by ", r_pid);
psignal(WTERMSIG(status), "signal");
}
}
else if (errno != ECHILD)
fprintf(stderr, "waitpid error: %s\n",
strerror(errno));
return;
}
开发者ID:Logic2soul,项目名称:csapp2E,代码行数:26,代码来源:myshell_release.c
示例12: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig) {
pid_t pid;
int status;
// Reap all the child process.
while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) {
//Handle with the 3 situation in this handler together.
if (WIFSIGNALED(status)) {
printf("Job [%d] (%d) terminated by Signal %d\n", pid2jid(pid),
pid,
WTERMSIG(status));
deletejob(jobs, pid);
} else if (
WIFSTOPPED(status)) {
struct job_t *job = getjobpid(jobs, pid);
if (job == NULL) {
printf("sigchld: Get job error.\n");
return;
}
job->state = ST;
printf("Job [%d] (%d) stopped by Signal %d\n", pid2jid(pid), pid,
WEXITSTATUS(status));
} else if (
WIFEXITED(status)) {
deletejob(jobs, pid);
}
//printf("Handler reaped child %d\n", (int)pid);
}
return;
}
开发者ID:FDUJiChao,项目名称:wdan-ics,代码行数:38,代码来源:tsh.c
示例13: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int status;
if (verbose) printf ("sigchld_handler: entering\n");
/* wait until some child is terminated */
pid_t pid_ch, jid_ch ;
while ((pid_ch = waitpid (-1, &status, WUNTRACED | WNOHANG)) > 0) { // wait any terminated child
jid_ch = pid2jid (pid_ch);
if (verbose) printf ("sigchld_handler: Job [%d] (%d) deleted\n", jid_ch, pid_ch);
if (WIFEXITED (status)) { // case 1: child process terminated normally
if (verbose) printf ("sigchld_handler: Job [%d] (%d) terminates OK (status 0)\n", jid_ch, pid_ch);
deletejob (jobs, pid_ch);
}
else if (WIFSIGNALED (status)) { // case 2: child process terminated via a signal that was not caught
deletejob (jobs, pid_ch);
printf ("Job [%d] (%d) terminated by signal %d\n", jid_ch, pid_ch, WTERMSIG (status));
}
else if (WIFSTOPPED (status)) { // case 3: child process stopped
struct job_t *stopped = getjobpid (jobs, pid_ch);
stopped->state = ST;
printf ("Job [%d] (%d) stopped by signal %d\n", jid_ch, pid_ch, WSTOPSIG (status));
}
}
if (verbose) printf ("sigchld_handler: exiting\n");
return;
}
开发者ID:sanha,项目名称:SP2015,代码行数:38,代码来源:tsh.c
示例14: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int status;
pid_t pid;
while ((pid = waitpid(fgpid(jobs), &status, WNOHANG|WUNTRACED)) > 0) {
if (WIFSTOPPED(status)){
//change state if stopped
getjobpid(jobs, pid)->state = ST;
int jid = pid2jid(pid);
printf("Job [%d] (%d) Stopped by signal %d\n", jid, pid, WSTOPSIG(status));
}
else if (WIFSIGNALED(status)){
//delete is signaled
int jid = pid2jid(pid);
printf("Job [%d] (%d) terminated by signal %d\n", jid, pid, WTERMSIG(status));
deletejob(jobs, pid);
}
else if (WIFEXITED(status)){
//exited
deletejob(jobs, pid);
}
}
return;
}
开发者ID:yyclaire,项目名称:ShellLab,代码行数:32,代码来源:tsh.c
示例15: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
//Throw out finished processes
//Change status to ST for stopped processes
int child_status;
pid_t culprit_pid; //pid of terminated or stopped child, 0 if no child terminated/stopped, -1 err
pid_t culprit_jid;
while((culprit_pid = waitpid(-1, &child_status, WNOHANG | WUNTRACED)) > 0)
{
culprit_jid = pid2jid(culprit_pid);
if (WIFEXITED(child_status))
{
//Child terminated normally, via a call to exit or a return
if (verbose)
printf("child %d exited normally\n", culprit_pid);
deletejob(jobs, culprit_pid);
}
else if (WIFSIGNALED(child_status))
{
//Child terminated because of a signal that was not caught
if (verbose)
printf("child %d exited because of a signal\n", culprit_pid);
deletejob(jobs, culprit_pid);
printf("Job [%d] (%d) terminated by signal %d", culprit_jid, culprit_pid, WTERMSIG(child_status));
printf("\n");
}
else if (WIFSTOPPED(child_status))
{
//Child that caused the return is stopped
if (verbose)
printf("child %d stopped\n", culprit_pid);
//Change job list state to stopped
struct job_t *myJob = getjobpid(jobs, culprit_pid);
myJob->state = ST;
printf("Job [%d] (%d) stopped by signal %d", culprit_jid, culprit_pid, WSTOPSIG(child_status));
printf("\n");
}
}
}
开发者ID:vucuong12,项目名称:CS_KAIST,代码行数:62,代码来源:tshref(sai11_12).c
示例16: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP, SIGTSTP, SIGTTIN or SIGTTOU signal. The
* handler reaps all available zombie children, but doesn't wait
* for any other currently running children to terminate.
*/
void sigchld_handler(int sig) {
int status;
pid_t pid;
int olderrno = errno; // store errno in handler
/*
* Reap child with the pid if the child is stopped or terminated
* If a child is terminated normally, delete the child from the job list
* If a child is stopped by a signal, set the job status as stopped
* If a child is terminated by a signal that was not caught, delete the child from the job list
*/
while ((pid = waitpid(-1, &status, WNOHANG|WUNTRACED)) > 0) {
if (WIFEXITED(status)) {
deletejob(job_list, pid); // the child ternimated normally
} else if (WIFSTOPPED(status)) {
/*
* Avoid printf() in handler, use helper function to write the output to stdout
*/
sio_puts("Job [");
sio_putl(pid2jid(pid));
sio_puts("] (");
sio_putl(pid);
sio_puts(") stopped by signal ");
sio_putl(WSTOPSIG(status));
sio_puts("\n");
getjobpid(job_list, pid) -> state = ST; // the child was stopped by a signal
} else if (WIFSIGNALED(status)) { // the child was terminated by a signal that was not caught
/*
* Avoid printf() in handler, use helper function to write the output to stdout
*/
sio_puts("Job [");
sio_putl(pid2jid(pid));
sio_puts("] (");
sio_putl(pid);
sio_puts(") terminated by signal ");
sio_putl(WTERMSIG(status));
sio_puts("\n");
deletejob(job_list, pid);
}
}
errno = olderrno;
return;
}
开发者ID:jianggao0612,项目名称:CSAPP15213,代码行数:62,代码来源:tsh.c
示例17: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig)
{
int child_status; // child process status for waitpid
pid_t wpid;
struct job_t *job;
// wait for child process while there is any child left
while(maxjid(jobs))
{
// -1 : wait for any child
// WNOHANG : don't block procedure
// WUNTRACED : trace stopped child
wpid = waitpid(-1, &child_status, WNOHANG | WUNTRACED);
if(wpid == -1)
{
// handle waitpid error
perror("waitpid");
return;
}
else if(wpid == 0)
{
// no child was terminated or stopped
break;
}
// find job object with pid
// getjobpid never fails
job = getjobpid(jobs, wpid);
// check child status
if(WIFSIGNALED(child_status))
{
// child terminated by a signal
printf("Job [%d] (%d) terminated by signal %d\n", job->jid, job->pid, WTERMSIG(child_status));
// delete job from job list
deletejob(jobs, wpid);
}
else if(WIFSTOPPED(child_status))
{
// child stopped
printf("Job [%d] (%d) stopped by signal %d\n", job->jid, job->pid, WSTOPSIG(child_status));
// set state
job->state = ST;
}
else if(WIFEXITED(child_status))
{
// child exited properly
// delete job from job list
deletejob(jobs, wpid);
}
}
}
开发者ID:protos37,项目名称:splab,代码行数:60,代码来源:tsh.c
示例18: sigchld_handler
void sigchld_handler(int sig) {
pid_t pid;
int status;
struct job *p;
if ((pid = waitpid(-1, &status, WUNTRACED)) > 0) {
if (WIFEXITED(status)) {
deletejob(pid);
if (pid == forepid) {
forepid = 0;
setpgid(pid, pid);
fprintf(stderr, "foreground job %d terminated normally with exit status=%d\n",
pid, WEXITSTATUS(status));
siglongjmp(env, 1);
}
else
fprintf(stderr, "job %d terminated normally with exit status=%d\n",
pid, WEXITSTATUS(status));
}
else if (WIFSTOPPED(status)) {
p = selectjob(pid);
p->state = 0;
if (pid == forepid) {
forepid = 0;
setpgid(pid, pid);
fprintf(stderr, "foreground job [%d] %d stopped by signal: Stopped\n",
p->jid, pid);
siglongjmp(env, 1);
}
else
fprintf(stderr, "job [%d] %d stopped by signal: Stopped\n",
p->jid, pid);
}
else if (WIFSIGNALED(status)) {
deletejob(pid);
if (pid == forepid) {
forepid = 0;
setpgid(pid, pid);
fprintf(stderr, "foreground job %d terminated by ", pid);
psignal(WTERMSIG(status), "signal");
siglongjmp(env, 1);
}
else
fprintf(stderr, "job %d terminated by ", pid);
psignal(WTERMSIG(status), "signal");
}
}
else if (errno != ECHILD)
fprintf(stderr, "waitpid error: %s\n", strerror(errno));
printf("handler reaped pid=%d, ready to return right now.\n", pid);
return;
}
开发者ID:Logic2soul,项目名称:csapp2E,代码行数:51,代码来源:myshell_bug2.c
示例19: sigchld_handler
/*
* sigchld_handler - The kernel sends a SIGCHLD to the shell whenever
* a child job terminates (becomes a zombie), or stops because it
* received a SIGSTOP or SIGTSTP signal. The handler reaps all
* available zombie children, but doesn't wait for any other
* currently running children to terminate.
*/
void sigchld_handler(int sig) {
int status; // Status
pid_t pid; // pid
struct job_t *pjob; // Pointer to job
do {
// Following directions from the link in the README
pid = waitpid(-1, &status, WNOHANG|WUNTRACED); // Using WNOHANG as spoken about in class
if (pid > 0) {
if (WIFSTOPPED(status)) {
// If stopped
if ((pjob = getjobpid(jobs, pid)) != NULL) {
// get job and change state
pjob->state = ST; // changing state
printf("Job [%d] (%d) stopped by signal 20\n", pjob->jid, pjob->pid);
} else {
// Job was invalid
printf("sigchld_handler: getjobpid error\n");
exit(1);
}
} else if (WIFSIGNALED(status)) {
// TODO: Find the link for the second tutorial
if ((pjob = getjobpid(jobs, pid)) != NULL) {
printf("Job [%d] (%d) terminated by signal 2\n", pjob->jid, pjob->pid);
if (!deletejob(jobs, pid)) { // Delete job
printf("sigchld_handler: deletejob error\n");
exit(1);
}
} else {
printf("sigchld_handler: getjobpid error\n");
exit(1);
}
} else if (WIFEXITED(status)) {
if (!deletejob(jobs, pid)) {
// DELETE JOB
printf("sigchld_handler: deletejob error\n");
exit(1);
}
} else {
printf("Unknown waitpid\n");
exit(1);
}
} else if (pid == -1 && errno == EINTR) {
continue;
} else {
break;
}
} while (1);
return;
}
开发者ID:sukritchhabra,项目名称:sc3349-cs283-winter2016,代码行数:57,代码来源:tsh.c
示例20: builtin_cmd
/*
* builtin_cmd - If the user has typed a built-in command then execute
* it immediately.
*/
int builtin_cmd(char **argv)
{
int r=0;
char* p;
int jobid;
if(strcmp(argv[0],"quit")==0)
{
r++;
exit(0);
}
else if(strcmp(argv[0],"jobs")==0)
{
r++;
listjobs(jobs);
}
else if((strcmp(argv[0],"bg")==0)||(strcmp(argv[0],"fg")==0))
{
r++;
do_bgfg(argv);
}
else if(strcmp(argv[0],"kill")==0)
{
r++;
p = strstr(argv[1],"%");
p++;
jobid=atoi(p); //Since jobid is specified as %5 for job 5 we get 5 from argv[1].
jobid=getjobjid(jobs,jobid)->pid;
kill(jobid,SIGKILL);
deletejob(jobs,jobid);
}
return r; /* not a builtin command */
}
开发者ID:vaibhav-495,项目名称:Shell,代码行数:36,代码来源:tsh.c
注:本文中的deletejob函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论