1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| void eval(char *cmdline) { char *argv[MAXARGS]; char buf[MAXLINE]; int bg; int jid; pid_t pid; sigset_t mask_all, mask_one, prev_one; sigfillset(&mask_all); sigemptyset(&mask_one); sigaddset(&mask_one, SIGCHLD);
strcpy(buf, cmdline); bg = parseline(buf, argv); if (argv[0] == NULL) return;
if (!builtin_cmd(argv)) { sigprocmask(SIG_BLOCK, &mask_one, &prev_one); if ((pid = fork()) == 0) { setpgid(0, 0); sigprocmask(SIG_SETMASK, &prev_one, NULL); if (execve(argv[0], argv, environ) < 0) { printf("%s: Command not found.\n", argv[0]); exit(0); } }
if (!bg) { sigprocmask(SIG_BLOCK, &mask_all, NULL); addjob(jobs, pid, FG, cmdline); sigprocmask(SIG_SETMASK, &prev_one, NULL); waitfg(pid); } else { sigprocmask(SIG_BLOCK, &mask_all, NULL); addjob(jobs, pid, BG, cmdline); sigprocmask(SIG_SETMASK, &prev_one, NULL); jid = pid2jid(pid); printf("[%d] (%d) %s", jid, pid, cmdline); } } return; }
|