当前位置: 首页>>代码示例>>C++>>正文


C++ deletejob函数代码示例

本文整理汇总了C++中deletejob函数的典型用法代码示例。如果您正苦于以下问题:C++ deletejob函数的具体用法?C++ deletejob怎么用?C++ deletejob使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了deletejob函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的deletejob函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。