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
|
void eval(char *cmdline) { char *argv[MAXARGS]; int bg; pid_t pid; sigset_t mask_child;
bg = parseline(cmdline, argv);
if (!builtin_cmd(argv)) { sigemptyset(&mask_child); sigaddset(&mask_child, SIGCHLD); sigprocmask(SIG_BLOCK, &mask_child, NULL);
if ((pid = fork()) == 0) { sigprocmask(SIG_UNBLOCK, &mask_child, NULL); setpgid(0, 0); if (execvp(argv[0], argv) < 0) { printf("%s: Command not found\n", argv[0]); exit(1); } } else { if (!bg) { addjob(jobs, pid, FG, cmdline); } else { addjob(jobs, pid, BG, cmdline); } if (!bg) { waitfg(pid); } else { printf("[%d] (%d) %s", pid2jid(pid), pid, cmdline); } sigprocmask(SIG_UNBLOCK, &mask_child, NULL); } } return; }
|