• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pid2jid函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了pid2jid函数的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 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 tmppid = 1;
	int st;

	while( tmppid > 0 ) { // default tmppid is 1.
		tmppid = waitpid(-1, &st, WNOHANG | WUNTRACED); // wait all children and with WNOHANG | WUNTRACED. 

		if(tmppid > 0) { // When child processes returns PID.
			if(WIFEXITED(st)) // When the child exits.
				deletejob(jobs, tmppid);
			else {
				if(WIFSIGNALED(st)) { 
					if(WTERMSIG(st) == 2) // If signal is 2(that is SIGINT)
						printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(tmppid), tmppid, WTERMSIG(st));
					deletejob(jobs, tmppid);
				}
				else if(WIFSTOPPED(st)) { // When child processes are stopped.
					getjobpid(jobs, tmppid)->state = ST; // Change state.
					printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(tmppid), tmppid, WSTOPSIG(st));
				}
			}
		}
	}
}
开发者ID:Hyunjin95,项目名称:System_Programming,代码行数:32,代码来源: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, 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;
	struct job_t* job;
	
	while ((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) {
		if (WIFSIGNALED(status)) {
			if (WTERMSIG(status) == SIGINT) {
				printf("Job [%d] (%d) terminated by signal %d\n",
					pid2jid(pid), pid, WTERMSIG(status));
				deletejob(job_list, pid);
			}
		}
		else if (WIFSTOPPED(status)) {
			job = getjobpid(job_list, pid);
				job->state = ST;
				printf("Job [%d] (%d) stopped by signal %d\n",
					pid2jid(pid), pid, WSTOPSIG(status));
		}
		else
			deletejob(job_list, pid);
	}
	if (pid == -1 && errno != ECHILD)
		unix_error("waitpid error");
	return;
}
开发者ID:zoulc,项目名称:CSAPP-Lab,代码行数:36,代码来源:tsh.c


示例3: 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){
        if(pid == fgpid(job_list)){
            if(tcgetpgrp(STDIN_FILENO) != shell_pid) {
                tcsetpgrp(STDIN_FILENO, shell_pid);
            }
        }
        if(WIFEXITED(status)){
            deletejob(job_list, pid);
        } else if(WIFSIGNALED(status)){
            printf("Job [%d] (%d) terminated by signal %d\n",
                   pid2jid(pid), pid, WTERMSIG(status));
            deletejob(job_list, pid);
        } else if (WIFSTOPPED(status)) {
            printf("Job [%d] (%d) stopped by signal %d\n", 
                   pid2jid(pid), pid, WSTOPSIG(status));
            getjobpid(job_list, pid)->state = ST;
        }
    }
    return;
}
开发者ID:YurieCo,项目名称:csapp-2,代码行数:32,代码来源:tsh.c


示例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) 
{
    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


示例5: 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


示例6: builtincont

void builtincont(struct cmdline_tokens *tok, int state){
  if (tok->argc < 2){
    // app_error("Usage: %s [%jid/pid]\n", tok->argv[0]);
    return;
  }
  pid_t pid;

  /* JID */
  if (tok->argv[1][0]=='%'){
    int jid = atoi((char *)(tok->argv[1] + sizeof(char)));
    pid = jid2pid(jid);
    if (!pid)
      app_error("No such jid \n");
  }
  else{
    /* PID case */
    pid = atoi(tok->argv[1]);
    if (!pid2jid(pid))
      app_error("No such pid \n");
  }
  /* Common to both JID & PID */
  Kill(-pid, SIGCONT);
  changestate(job_list, pid, state);
  if (state==BG){
    printf("[%d] (%d) %s\n", pid2jid(pid), pid,
	   getjobpid(job_list,pid)->cmdline);
  }

  if (state==FG){
    wait_for_fg(pid);
  }
}
开发者ID:MyMiracle,项目名称:Shell-Lab,代码行数:32,代码来源: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, 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;
    
    while((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0) {
        if(WIFEXITED(status)) {
            /* if a child job terminated normally */
            deletejob(job_list, pid);

        } else if(WIFSIGNALED(status)) {
            /* if a child job terminated by signal */
            printf("Job [%d] (%d) terminated by signal %d\n",
                pid2jid(pid), pid, WTERMSIG(status));
            deletejob(job_list, pid);

        } else if(WIFSTOPPED(status)) {
            /* if a child job is stopped, we should also update its status */
            printf("Job [%d] (%d) stopped by signal %d\n",
                pid2jid(pid), pid, WSTOPSIG(status));
            getjobpid(job_list, pid) -> state = ST;
        }
    }
        
    return;
}
开发者ID:kuoliu,项目名称:15213,代码行数:32,代码来源: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) 
{
int pid,status;
    while ((pid=waitpid(-1, &status, WNOHANG | WUNTRACED))>0)
    {
        /*If there is any child which is still running then parent will not wait for them and retuens the pids and status of reaped child with MACRO  "WNOHANG".*/
/* Also if there are any stopped ot terminated child then parent will reap them immediately with MACRO "WUNTRACED"*/ 

        if (WIFEXITED(status))/* MACRO "WIFEXITED" returns true if child terminated normally*/
            {
                deletejob(jobs, pid); /* delete job from jobtable when terminated*/                     
            }
        else if (WIFSIGNALED(status))/* MACRO "WIFSIGNALED" returns true if reaped child is terminated*/
        {
            printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status));/*MACRO "WTERMSIG" gives by which signal child is terminated*/           
            deletejob(jobs, pid); /* delete job from jobtable when terminated*/                     
        }
        else if (WIFSTOPPED(status))/* MACRO "WIFSTOPPED" returns true if reaped child is stopped*/
        {
            getjobpid(jobs, pid)->state = ST; /* If child process receives stop signal then it will change state of child process*/
            printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(pid), pid, WSTOPSIG(status)); /*MACRO "WSTOPSIG" gives by which signal child is stopped*/
        }
    }
    return;
}
开发者ID:ajpatel910,项目名称:tiny-shell,代码行数:32,代码来源: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, 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; 

  while((pid = waitpid(-1, &status, WUNTRACED | WNOHANG)) > 0)
  {
  
    // If child exited normally, delete job from list
    if(WIFEXITED(status))
      deletejob(job_list, pid);

    // If child terminated because of uncaught signal, delete job from list
    else if(WIFSIGNALED(status))
    {
      printf("Job [%d] (%d) terminated by signal %d\n", 
	     pid2jid(pid), pid, WTERMSIG(status));
      
      deletejob(job_list, pid);
    }

    // If child was stopped change status to ST
    else if(WIFSTOPPED(status))
    {     
      printf("Job [%d] (%d) stopped by signal %d\n",
	     pid2jid(pid), pid, WSTOPSIG(status));

      getjobpid(job_list, pid) -> state = ST;
    }
  }

  return;

}
开发者ID:nabilmurshed,项目名称:Unix-Shell,代码行数:42,代码来源:tsh.c


示例10: sigchld_handler

void sigchld_handler(int sig) 
{
    pid_t pid = 0;
    struct job_t *nowjob = 0;
    int status;
    while((pid = waitpid(-1, &status, WNOHANG | WUNTRACED)) > 0)//handle all stopped or terminated children
    {
        if(WIFEXITED(status))
        {
         //   printf("pid [%d] terminated normally\n",pid);
            deletejob(jobs,pid);
        }
        else if(WIFSIGNALED(status))
        {
            printf("Job [%d] (%d) terminated by signal %d\n",pid2jid(pid),pid,WTERMSIG(status));
            deletejob(jobs,pid);
        }
        else if(WIFSTOPPED(status))
        {
            printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(pid), pid, WSTOPSIG(status));
            nowjob = getjobpid(jobs,pid);
            nowjob->state = ST;
        }
    }
    if((errno != ECHILD) && (errno != 0)) 
    {
        unix_error("waitpid error");
    }   
        
    
    return;
}
开发者ID:wwiiiii,项目名称:CS230-KAIST,代码行数:32,代码来源:tsh.c


示例11: 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


示例12: sigchld_handler

void sigchld_handler(int sig) 
{
	int pid=0;
    int status=-1;
    do{     //continually reap as many children as possible, deleting them from the job list
        pid=waitpid(-1,&status,WNOHANG|WUNTRACED);   
       
        if(pid>0)//first time
        {
            if(WIFEXITED(status)){//child terminated normally, easy to handle, just delete it from the job list
                deletejob(jobs,pid);
               
            }
            else
            if(WIFSIGNALED(status)){  //what if the process was terminated by another process?
                if(WTERMSIG(status)==2)
                    printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status));
                deletejob(jobs,pid);
            }
            else if(WIFSTOPPED(status)){    //what if the process was stopped by another process?
                getjobpid(jobs, pid)->state=ST;
                printf("Job [%d] (%d) stopped by signal %d\n", pid2jid(pid), pid, WSTOPSIG(status));
            }
        }        
    }
    while(pid>0);
}
开发者ID:FakerLulu,项目名称:syspro,代码行数:27,代码来源: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, 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


示例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;
    waitpid(-1, &status, 0);
    return;
    */
    
    //printf("...in sigchild\n");
    fflush(stdout);
    int status = 1;
    pid_t pid;
    while ( ( pid = waitpid(-1, &status, WNOHANG | WUNTRACED) ) > 0 )
    {
        if (WIFSTOPPED(status))
        {
            int jid = pid2jid(pid);
            getjobpid(jobs, pid)->state = ST;
            printf("%s [%d] (%d) %s %d %s", "Job", jid, pid, "stopped by signal", SIGSTOP, "\n");
        }
        else
        {
            int jid = pid2jid(pid);
            int jdel = deletejob(jobs, pid);
            if (jdel)
            {
                if (sig != 17)
                {
                    //printf("MADE IT!\n");
                    printf("%s [%d] (%d) %s %d %s", "Job", jid, pid, "terminated by signal", SIGINT, "\n");
                }
            }
            else
            {
                printf("error deleting job\n");
                fflush(stdout);
                exit(1);
            }  
        }
        
    }
    if (pid == -1)
    {
        //printf("...no processes\n");
    }
    else if (pid < -1)
    {
        printf("error in sigchild\n");
        fflush(stdout);
        exit(1);
    }
    
    return;
}
开发者ID:nmank,项目名称:comp-organization,代码行数:61,代码来源: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)
{
	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


示例16: 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


示例17: eval

/* 
 * eval - Evaluate the command line that the user has just typed in
 * 
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately. Otherwise, fork a child process and
 * run the job in the context of the child. If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.  
*/
void eval(char *cmdline) 
{
  
	char *argv[MAXARGS];
	int bg=parseline(cmdline,argv);
        int  p=builtin_cmd(&argv[0]);
	int childpid;
	bg++;                //because the background process is defined as  2 and foreground as 1
        sigset_t set;
        sigemptyset(&set);
        sigaddset(&set,SIGCHLD);
        sigaddset(&set,SIGINT);
        sigaddset(&set,SIGTSTP);
        if(!p)
        {       
                if((childpid=fork())==0)
		{
			setpgid(0,0); //Changing group id
			execve(argv[0], argv, NULL);
                        printf("Command not found\n");//If incase there is no command
		        exit(0);
		}
                else
		{    
			sigprocmask(SIG_BLOCK,&set,NULL); //masking if incase child executes first
		        addjob(jobs,childpid,bg,cmdline);
                        sigprocmask(SIG_UNBLOCK,&set,NULL);//remove mask
                        if(bg==1) 
                        	waitfg(childpid);
	           	else
                   		printf("[%d] (%d) %s",pid2jid(childpid),childpid,cmdline);
                }
	}
	return;
}
开发者ID:vaibhav-495,项目名称:Shell,代码行数:46,代码来源:tsh.c


示例18: eval

/*
 * eval - Evaluate the command line that the user has just typed in
 *
 * If the user has requested a built-in command (quit, jobs, bg or fg)
 * then execute it immediately. Otherwise, fork a child process and
 * run the job in the context of the child. If the job is running in
 * the foreground, wait for it to terminate and then return.  Note:
 * each child process must have a unique process group ID so that our
 * background children don't receive SIGINT (SIGTSTP) from the kernel
 * when we type ctrl-c (ctrl-z) at the keyboard.
*/
void eval(char *cmdline)
{
    char *argv[MAXARGS]; /* argv for execve() */
    int bg;
    pid_t pid;

    bg = parseline(cmdline, argv);
    if(argv[0] == NULL) return; /* ignore empty lines */

    if(!builtin_cmd(argv))
    {
        if((pid = fork()) < 0) unix_error("eval(): fork() error");

        if(pid == 0) /* child runs user job */
	{
            if(setpgid(0,0) < 0) unix_error("eval(): setpgid() error");

            if(execve(argv[0], argv, environ) < 0)
            {
                printf("%s: Command not found.\n", argv[0]);
                exit(0);
            }
        }

	addjob(jobs,pid,(bg == 1 ? BG : FG),cmdline);

	sigprocmask(SIG_UNBLOCK,&mask,NULL);

	if(!bg) waitfg(pid);
	else printf("[%d] (%d) %s",pid2jid(pid),pid,cmdline);
    }

    return;
}
开发者ID:aarsee,项目名称:Shell-Script,代码行数:45,代码来源:tsh.c


示例19: eval

/* 
	* eval - Evaluate the command line that the user has just typed in
	* 
	* If the user has requested a built-in command (quit, jobs, bg or fg)
	* then execute it immediately. Otherwise, fork a child process and
	* run the job in the context of the child. If the job is running in
	* the foreground, wait for it to terminate and then return.  Note:
	* each child process must have a unique process group ID so that our
	* background children don't receive SIGINT (SIGTSTP) from the kernel
	* when we type ctrl-c (ctrl-z) at the keyboard.  
	*/
void eval(char *cmdline) 
{
	char *argv[MAXARGS];
	/* int ground = parseline(cmdline, (char **)&argv); */
	char buf[MAXLINE];      // Holds modified command line
	strcpy(buf, cmdline);
	int ground = parseline(buf, argv);

	if (argv[0] == NULL) return;

	if (!builtin_cmd((char **)&argv)) {
		sigset_t mask;
		sigemptyset(&mask);
		sigaddset(&mask, SIGCHLD);
		sigprocmask(SIG_BLOCK, &mask, NULL);
		pid_t pid = __fork();

		if (pid != 0) {
			addjob(jobs, pid, ground ? BG : FG, cmdline);
			sigprocmask(SIG_UNBLOCK, &mask, NULL);
			if (!ground) waitfg(pid);
			else printf("[%d] (%d) %s", pid2jid(pid), pid, cmdline);
		} else {
			__setpgid(0, 0);
			sigprocmask(SIG_UNBLOCK, &mask, NULL);
			if (execve(argv[0], argv, environ) < 0) {
				printf("%s: Command not found\n", argv[0]);
				exit(0);
			}
		}
	}

	return;
}
开发者ID:MintPaw,项目名称:College,代码行数:45,代码来源:tsh.c


示例20: 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;
    struct job_t *job;
    int old_err = errno;

    while((pid = waitpid(-1, &status, WNOHANG|WUNTRACED)) > 0 ) {
        if(WIFSTOPPED(status)) {
            job = getjobpid(job_list, pid);
            //Assume that pointer job is not NULL
            safe_printf("Job [%d] (%d) stopped by signal %d\n", job->jid, job->pid, WSTOPSIG(status));
            job->state = ST;
        }
        else if(WIFSIGNALED(status)) {
            safe_printf("Job [%d] (%d) terminated by signal %d\n", pid2jid(pid), pid, WTERMSIG(status));
            deletejob(job_list,pid);
        }
        else if(WIFEXITED(status)) 
            deletejob(job_list,pid);
    }

    if( pid < 0 && errno != ECHILD && errno != EINTR ) {
        safe_printf("waitpid error: %s\n", strerror(errno));
        _exit(1);
    }

    errno = old_err;
    return;
}
开发者ID:jessesleeping,项目名称:15213labs,代码行数:38,代码来源:tsh.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pid_alive函数代码示例发布时间:2022-05-30
下一篇:
C++ pid函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap