X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/2d4bbda8b192098dbdae10b1fe283bd6e22e846f..3ffa6b49df5b42905c5290d9e6c4e71de0d15fd6:/usr/src/bin/csh/proc.c diff --git a/usr/src/bin/csh/proc.c b/usr/src/bin/csh/proc.c index 5900010f1d..ee9735dc9c 100644 --- a/usr/src/bin/csh/proc.c +++ b/usr/src/bin/csh/proc.c @@ -1,9 +1,9 @@ -static char *sccsid = "@(#)proc.c 4.1 %G%"; +static char *sccsid = "@(#)proc.c 4.12 (Berkeley) 83/07/01"; #include "sh.h" #include "sh.dir.h" #include "sh.proc.h" -#include +#include #include /* @@ -26,19 +26,13 @@ pchild() register int pid; union wait w; int jobflags; -#ifdef VMUNIX - struct vtimes vt; -#endif + struct rusage ru; if (!timesdone) timesdone++, times(&shtimes); loop: pid = wait3(&w.w_status, (setintr ? WNOHANG|WUNTRACED:WNOHANG), -#ifndef VMUNIX - 0); -#else - &vt); -#endif + &ru); if (pid <= 0) { if (errno == EINTR) { errno = 0; @@ -63,15 +57,13 @@ found: time_t oldcutimes, oldcstimes; oldcutimes = shtimes.tms_cutime; oldcstimes = shtimes.tms_cstime; - time(&pp->p_etime); + gettimeofday(&pp->p_etime, (struct timezone *)0); times(&shtimes); pp->p_utime = shtimes.tms_cutime - oldcutimes; pp->p_stime = shtimes.tms_cstime - oldcstimes; } else times(&shtimes); -#ifdef VMUNIX - pp->p_vtimes = vt; -#endif + pp->p_rusage = ru; if (WIFSIGNALED(w)) { if (w.w_termsig == SIGINT) pp->p_flags |= PINTERRUPTED; @@ -82,11 +74,7 @@ found: pp->p_reason = w.w_termsig; } else { pp->p_reason = w.w_retcode; -#ifdef IIASA - if (pp->p_reason >= 3) -#else if (pp->p_reason != 0) -#endif pp->p_flags |= PAEXITED; else pp->p_flags |= PNEXITED; @@ -115,23 +103,24 @@ found: } while((fp = fp->p_friends) != pp); while(fp->p_pid != fp->p_jobid) fp = fp->p_friends; + if (jobflags&PSTOPPED) { + if (pcurrent && pcurrent != fp) + pprevious = pcurrent; + pcurrent = fp; + } else + pclrcurr(fp); if (jobflags&PFOREGND) { - if (jobflags&PSTOPPED) { - if (pcurrent && pcurrent != fp) - pprevious = pcurrent; - pcurrent = fp; - } else - pclrcurr(fp); if (jobflags & (PSIGNALED|PSTOPPED|PPTIME) || #ifdef IIASA jobflags & PAEXITED || #endif !eq(dcwd->di_name, fp->p_cwd->di_name)) { - if (jobflags & PSTOPPED) - printf("\n"); - pprint(fp, AREASON|SHELLDIR); - } else if ((jobflags & (PTIME|PSTOPPED)) == PTIME) + ; /* print in pjwait */ + } +/* + else if ((jobflags & (PTIME|PSTOPPED)) == PTIME) ptprint(fp); +*/ } else { if (jobflags&PNOTIFY || adrof("notify")) { printf("\215\n"); @@ -139,8 +128,6 @@ found: if ((jobflags&PSTOPPED) == 0) pflush(pp); } else { - if ((jobflags&PSTOPPED) == 0) - pclrcurr(fp); fp->p_flags |= PNEEDNOTE; neednote++; } @@ -205,6 +192,8 @@ pjwait(pp) register struct process *fp; int jobflags, reason; + while (pp->p_pid != pp->p_jobid) + pp = pp->p_friends; fp = pp; do { if ((fp->p_flags&(PFOREGND|PRUNNING)) == PRUNNING) @@ -223,17 +212,22 @@ pjwait(pp) while((fp = (fp->p_friends)) != pp); if ((jobflags & PRUNNING) == 0) break; - sigpause(SIGCHLD); + sigpause(sigblock(0) &~ mask(SIGCHLD)); } sigrelse(SIGCHLD); if (tpgrp > 0) ioctl(FSHTTY, TIOCSPGRP, &tpgrp); /* get tty back */ - if (jobflags & PSTOPPED) - return; - if ((jobflags&PINTERRUPTED) && setintr && + if ((jobflags&(PSIGNALED|PSTOPPED|PTIME)) || + !eq(dcwd->di_name, fp->p_cwd->di_name)) { + if (jobflags&PSTOPPED) + printf("\n"); + pprint(pp, AREASON|SHELLDIR); + } + if ((jobflags&(PINTERRUPTED|PSTOPPED)) && setintr && (!gointr || !eq(gointr, "-"))) { - pflush(pp); - pintr(); + if ((jobflags & PSTOPPED) == 0) + pflush(pp); + pintr1(0); /*NOTREACHED*/ } reason = 0; @@ -262,9 +256,9 @@ dowait() loop: sighold(SIGCHLD); for (pp = proclist.p_next; pp; pp = pp->p_next) - if (pp->p_pid && pp->p_pid == pp->p_jobid && + if (pp->p_pid && /* pp->p_pid == pp->p_jobid && */ pp->p_flags&PRUNNING) { - sigpause(SIGCHLD); + sigpause(sigblock(0) &~ mask(SIGCHLD)); goto loop; } sigrelse(SIGCHLD); @@ -392,7 +386,9 @@ palloc(pid, t) for (np = proclist.p_next; np; np = np->p_next) if (np->p_index == i) goto tryagain; - pmaxindex = pp->p_index = i; + pp->p_index = i; + if (i > pmaxindex) + pmaxindex = i; break; tryagain:; } @@ -404,7 +400,7 @@ palloc(pid, t) } pp->p_next = proclist.p_next; proclist.p_next = pp; - time(&pp->p_btime); + gettimeofday(&pp->p_btime, (struct timezone *)0); } padd(t) @@ -626,11 +622,10 @@ prcomd: if (pp->p_flags&PPTIME && !(status&(PSTOPPED|PRUNNING))) { if (linp != linbuf) printf("\n\t"); -#ifndef VMUNIX - ptimes(pp->p_utime, pp->p_stime, pp->p_etime-pp->p_btime); -#else - pvtimes(&zvms, &pp->p_vtimes, pp->p_etime - pp->p_btime); -#endif + { static struct rusage zru; + prusage(&zru, &pp->p_rusage, &pp->p_etime, + &pp->p_btime); + } } if (tp == pp->p_friends) { if (linp != linbuf) @@ -653,30 +648,21 @@ prcomd: ptprint(tp) register struct process *tp; { - time_t tetime = 0; -#ifdef VMUNIX - struct vtimes vmt; -#else - time_t tutime = 0, tstime = 0; -#endif + struct timeval tetime, diff; + static struct timeval ztime; + struct rusage ru; + static struct rusage zru; register struct process *pp = tp; - vmt = zvms; + ru = zru; + tetime = ztime; do { -#ifdef VMUNIX - vmsadd(&vmt, &pp->p_vtimes); -#else - tutime += pp->p_utime; - tstime += pp->p_stime; -#endif - if (pp->p_etime - pp->p_btime > tetime) - tetime = pp->p_etime - pp->p_btime; + ruadd(&ru, &pp->p_rusage); + tvsub(&diff, &pp->p_etime, &pp->p_btime); + if (timercmp(&diff, &tetime, >)) + tetime = diff; } while ((pp = pp->p_friends) != tp); -#ifdef VMUNIX - pvtimes(&zvms, &vmt, tetime); -#else - ptimes(tutime, tstime, tetime); -#endif + prusage(&zru, &ru, &tetime, &ztime); } /* @@ -827,6 +813,7 @@ pkill(v, signum) register struct process *pp, *np; register int jobflags = 0; int pid; + char *cp; extern char *sys_errlist[]; int err = 0; @@ -834,8 +821,9 @@ pkill(v, signum) sighold(SIGINT); sighold(SIGCHLD); while (*v) { - if (**v == '%') { - np = pp = pfind(*v); + cp = globone(*v); + if (*cp == '%') { + np = pp = pfind(cp); do jobflags |= np->p_flags; while ((np = np->p_friends) != pp); @@ -846,7 +834,7 @@ pkill(v, signum) case SIGTTIN: case SIGTTOU: if ((jobflags & PRUNNING) == 0) { - printf("%s: Already stopped\n", *v); + printf("%s: Already stopped\n", cp); err++; goto cont; } @@ -854,10 +842,10 @@ pkill(v, signum) killpg(pp->p_jobid, signum); if (signum == SIGTERM || signum == SIGHUP) killpg(pp->p_jobid, SIGCONT); - } else if (!digit(**v)) + } else if (!digit(*cp)) bferr("Arguments should be jobs or process id's"); else { - pid = atoi(*v); + pid = atoi(cp); if (kill(pid, signum) < 0) { printf("%d: ", pid); printf("%s\n", sys_errlist[errno]); @@ -868,6 +856,7 @@ pkill(v, signum) kill(pid, SIGCONT); } cont: + xfree(cp); v++; } sigrelse(SIGCHLD); @@ -900,6 +889,8 @@ pstart(pp, foregnd) np->p_flags &= ~PFOREGND; } } while((np = np->p_friends) != pp); + if (!foregnd) + pclrcurr(pp); pprint(pp, foregnd ? NAME|JOBDIR : NUMBER|NAME|AMPERSAND); if (foregnd) ioctl(FSHTTY, TIOCSPGRP, &pp->p_jobid); @@ -968,20 +959,24 @@ match: } /* - * pgetcurr - find a job that is not pp and ``most recent'' + * pgetcurr - find most recent job that is not pp, preferably stopped */ struct process * pgetcurr(pp) register struct process *pp; { register struct process *np; + register struct process *xp = PNULL; for (np = proclist.p_next; np; np = np->p_next) if (np != pcurrent && np != pp && np->p_pid && np->p_pid == np->p_jobid) { - return (np); + if (np->p_flags & PSTOPPED) + return (np); + if (xp == PNULL) + xp = np; } - return (PNULL); + return (xp); } /*