Lines Matching refs:j
281 Job *j; in j_exit() local
284 for (j = job_list; j != NULL; j = j->next) { in j_exit()
285 if (j->ppid == procpid && in j_exit()
286 (j->state == PSTOPPED || in j_exit()
287 (j->state == PRUNNING && in j_exit()
288 ((j->flags & JF_FG) || in j_exit()
291 if (j->pgrp == 0) in j_exit()
292 kill_job(j, SIGHUP); in j_exit()
294 mksh_killpg(j->pgrp, SIGHUP); in j_exit()
296 if (j->state == PSTOPPED) { in j_exit()
297 if (j->pgrp == 0) in j_exit()
298 kill_job(j, SIGCONT); in j_exit()
300 mksh_killpg(j->pgrp, SIGCONT); in j_exit()
440 Job *j; in exchild() local
473 j = last_job; in exchild()
479 j = new_job(); in exchild()
484 j->flags = (flags & XXCOM) ? JF_XXCOM : in exchild()
486 timerclear(&j->usrtime); in exchild()
487 timerclear(&j->systime); in exchild()
488 j->state = PRUNNING; in exchild()
489 j->pgrp = 0; in exchild()
490 j->ppid = procpid; in exchild()
491 j->age = ++njobs; in exchild()
492 j->proc_list = p; in exchild()
493 j->coproc_id = 0; in exchild()
494 last_job = j; in exchild()
496 put_job(j, PJ_PAST_STOPPED); in exchild()
514 kill_job(j, SIGKILL); in exchild()
515 remove_job(j, "fork failed"); in exchild()
528 if (j->pgrp == 0) { in exchild()
530 j->pgrp = p->pid; in exchild()
538 setpgid(p->pid, j->pgrp); in exchild()
540 tcsetpgrp(tty_fd, j->pgrp); in exchild()
587 remove_job(j, "child"); in exchild()
616 j_startjob(j); in exchild()
618 j->coproc_id = coproc.id; in exchild()
622 coproc.job = (void *)j; in exchild()
625 j_set_async(j); in exchild()
627 shf_fprintf(shl_out, "[%d]", j->job); in exchild()
628 for (p = j->proc_list; p; p = p->next) in exchild()
635 rv = j_waitj(j, jwflags, "jw:last proc"); in exchild()
671 Job *j; in waitlast() local
678 j = last_job; in waitlast()
679 if (!j || !(j->flags & JF_STARTED)) { in waitlast()
680 if (!j) in waitlast()
691 rv = j_waitj(j, JW_NONE, "waitlast"); in waitlast()
705 Job *j; in waitfor() local
719 for (j = job_list; j; j = j->next) in waitfor()
721 if (j->ppid == procpid && j->state == PRUNNING) in waitfor()
723 if (!j) { in waitfor()
729 } else if ((j = j_lookup(cp, &ecode))) { in waitfor()
732 if (j->ppid != procpid) { in waitfor()
748 rv = j_waitj(j, flags, "jw:waitfor"); in waitfor()
765 Job *j; in j_kill() local
773 if ((j = j_lookup(cp, &ecode)) == NULL) { in j_kill()
781 if (j->pgrp == 0) { in j_kill()
783 if (kill_job(j, sig) < 0) { in j_kill()
789 if (j->state == PSTOPPED && (sig == SIGTERM || sig == SIGHUP)) in j_kill()
790 mksh_killpg(j->pgrp, SIGCONT); in j_kill()
792 if (mksh_killpg(j->pgrp, sig) < 0) { in j_kill()
810 Job *j; in j_resume() local
818 if ((j = j_lookup(cp, &ecode)) == NULL) { in j_resume()
824 if (j->pgrp == 0) { in j_resume()
831 shprintf("[%d] ", j->job); in j_resume()
834 for (p = j->proc_list; p != NULL; p = p->next) { in j_resume()
847 j->state = PRUNNING; in j_resume()
849 put_job(j, PJ_PAST_STOPPED); in j_resume()
851 j_set_async(j); in j_resume()
854 if (j->state == PRUNNING) { in j_resume()
855 if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) in j_resume()
856 mksh_tcset(tty_fd, &j->ttystat); in j_resume()
859 tcsetpgrp(tty_fd, (j->flags & JF_SAVEDTTYPGRP) ? in j_resume()
860 j->saved_ttypgrp : j->pgrp) < 0) { in j_resume()
862 if (j->flags & JF_SAVEDTTY) in j_resume()
867 (long)((j->flags & JF_SAVEDTTYPGRP) ? in j_resume()
868 j->saved_ttypgrp : j->pgrp), "failed", in j_resume()
873 j->flags |= JF_FG; in j_resume()
874 j->flags &= ~JF_KNOWN; in j_resume()
875 if (j == async_job) in j_resume()
879 if (j->state == PRUNNING && mksh_killpg(j->pgrp, SIGCONT) < 0) { in j_resume()
883 j->flags &= ~JF_FG; in j_resume()
884 if (ttypgrp_ok && (j->flags & JF_SAVEDTTY)) in j_resume()
898 j->flags &= ~(JF_SAVEDTTY | JF_SAVEDTTYPGRP); in j_resume()
900 rv = j_waitj(j, JW_NONE, "jw:resume"); in j_resume()
911 Job *j; in j_stopped_running() local
914 for (j = job_list; j != NULL; j = j->next) { in j_stopped_running()
916 if (j->ppid == procpid && j->state == PSTOPPED) in j_stopped_running()
920 j->ppid == procpid && j->state == PRUNNING) in j_stopped_running()
941 Job *j, *tmp; in j_jobs() local
957 if ((j = j_lookup(cp, &ecode)) == NULL) { in j_jobs()
965 j = job_list; in j_jobs()
967 for (; j; j = j->next) { in j_jobs()
968 if ((!(j->flags & JF_ZOMBIE) || zflag) && in j_jobs()
969 (!nflag || (j->flags & JF_CHANGED))) { in j_jobs()
970 j_print(j, how, shl_stdout); in j_jobs()
971 if (j->state == PEXITED || j->state == PSIGNALLED) in j_jobs()
972 j->flags |= JF_REMOVE; in j_jobs()
978 for (j = job_list; j; j = tmp) { in j_jobs()
979 tmp = j->next; in j_jobs()
980 if (j->flags & JF_REMOVE) in j_jobs()
981 remove_job(j, "jobs"); in j_jobs()
993 Job *j, *tmp; in j_notify() local
999 for (j = job_list; j; j = j->next) { in j_notify()
1001 if (Flag(FMONITOR) && (j->flags & JF_CHANGED)) in j_notify()
1002 j_print(j, JP_MEDIUM, shl_out); in j_notify()
1008 if (j->state == PEXITED || j->state == PSIGNALLED) in j_notify()
1009 j->flags |= JF_REMOVE; in j_notify()
1011 for (j = job_list; j; j = tmp) { in j_notify()
1012 tmp = j->next; in j_notify()
1013 if (j->flags & JF_REMOVE) in j_notify()
1014 remove_job(j, "notify"); in j_notify()
1048 j_set_async(Job *j) in j_set_async() argument
1054 if (!(j->flags & JF_STARTED)) { in j_set_async()
1058 async_job = j; in j_set_async()
1059 async_pid = j->last_proc->pid; in j_set_async()
1085 j_startjob(Job *j) in j_startjob() argument
1089 j->flags |= JF_STARTED; in j_startjob()
1090 for (p = j->proc_list; p->next; p = p->next) in j_startjob()
1092 j->last_proc = p; in j_startjob()
1109 j_waitj(Job *j, in j_waitj() argument
1123 j->flags |= JF_WAITING; in j_waitj()
1125 j->flags |= JF_W_ASYNCNOTIFY; in j_waitj()
1132 while (j->state == PRUNNING || in j_waitj()
1133 ((flags & JW_STOPPEDWAIT) && j->state == PSTOPPED)) { in j_waitj()
1147 int oldf = j->flags & (JF_WAITING|JF_W_ASYNCNOTIFY); in j_waitj()
1148 j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY); in j_waitj()
1151 j->flags |= oldf; in j_waitj()
1154 j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY); in j_waitj()
1158 j->flags &= ~(JF_WAITING|JF_W_ASYNCNOTIFY); in j_waitj()
1160 if (j->flags & JF_FG) { in j_waitj()
1161 j->flags &= ~JF_FG; in j_waitj()
1163 if (Flag(FMONITOR) && ttypgrp_ok && j->pgrp) { in j_waitj()
1175 if (j->state == PSTOPPED && in j_waitj()
1176 (j->saved_ttypgrp = tcgetpgrp(tty_fd)) >= 0) in j_waitj()
1177 j->flags |= JF_SAVEDTTYPGRP; in j_waitj()
1182 if (j->state == PSTOPPED) { in j_waitj()
1183 j->flags |= JF_SAVEDTTY; in j_waitj()
1184 mksh_tcget(tty_fd, &j->ttystat); in j_waitj()
1198 if (j->state == PEXITED && j->status == 0 && in j_waitj()
1199 (j->flags & JF_USETTYMODE)) { in j_waitj()
1215 if (j->state == PSTOPPED) in j_waitj()
1216 j->flags &= ~JF_USETTYMODE; in j_waitj()
1229 status = j->last_proc->status; in j_waitj()
1230 if (Flag(FMONITOR) && j->state == PSIGNALLED && in j_waitj()
1238 j_usrtime = j->usrtime; in j_waitj()
1239 j_systime = j->systime; in j_waitj()
1240 rv = j->status; in j_waitj()
1242 if (!(p = j->proc_list)) { in j_waitj()
1286 && (!Flag(FMONITOR) || j->state != PSTOPPED) in j_waitj()
1289 j_print(j, JP_SHORT, shl_out); in j_waitj()
1292 if (j->state != PSTOPPED in j_waitj()
1297 remove_job(j, where); in j_waitj()
1312 Job *j; in j_sigchld() local
1331 for (j = job_list; j; j = j->next) in j_sigchld()
1332 if (j->ppid == procpid && !(j->flags & JF_STARTED)) { in j_sigchld()
1360 for (j = job_list; j != NULL; j = j->next) in j_sigchld()
1361 for (p = j->proc_list; p != NULL; p = p->next) in j_sigchld()
1365 if (j == NULL) { in j_sigchld()
1374 timeradd(&j->usrtime, &ru1.ru_utime, &j->usrtime); in j_sigchld()
1375 timersub(&j->usrtime, &ru0.ru_utime, &j->usrtime); in j_sigchld()
1376 timeradd(&j->systime, &ru1.ru_stime, &j->systime); in j_sigchld()
1377 timersub(&j->systime, &ru0.ru_stime, &j->systime); in j_sigchld()
1386 p->state = j->state = PRUNNING; in j_sigchld()
1398 check_job(j); in j_sigchld()
1422 check_job(Job *j) in check_job() argument
1428 if (!(j->flags & JF_STARTED)) { in check_job()
1430 j->flags); in check_job()
1435 for (p=j->proc_list; p != NULL; p = p->next) { in check_job()
1442 j->state = jstate; in check_job()
1443 j->status = proc_errorlevel(j->last_proc); in check_job()
1450 if (j->state == PEXITED || j->state == PSIGNALLED) { in check_job()
1455 if (coproc.job == j) { in check_job()
1466 if (j->coproc_id && j->coproc_id == coproc.id && in check_job()
1471 j->flags |= JF_CHANGED; in check_job()
1473 if (Flag(FMONITOR) && !(j->flags & JF_XXCOM)) { in check_job()
1478 if (j->state == PSTOPPED) in check_job()
1479 put_job(j, PJ_ON_FRONT); in check_job()
1481 (j->flags & (JF_WAITING|JF_W_ASYNCNOTIFY)) != JF_WAITING) { in check_job()
1497 j_print(j, JP_MEDIUM, shl_j); in check_job()
1499 if (!(j->flags & JF_WAITING) && j->state != PSTOPPED) in check_job()
1500 remove_job(j, "notify"); in check_job()
1508 !(j->flags & (JF_WAITING|JF_FG)) && in check_job()
1509 j->state != PSTOPPED) { in check_job()
1510 if (j == async_job || (j->flags & JF_KNOWN)) { in check_job()
1511 j->flags |= JF_ZOMBIE; in check_job()
1512 j->job = -1; in check_job()
1515 remove_job(j, "checkjob"); in check_job()
1525 j_print(Job *j, int how, struct shf *shf) in j_print() argument
1542 shf_fprintf(shf, "%d\n", (int)(j->pgrp ? j->pgrp : in j_print()
1543 (j->last_proc ? j->last_proc->pid : 0))); in j_print()
1546 j->flags &= ~JF_CHANGED; in j_print()
1547 filler = j->job > 10 ? "\n " : "\n "; in j_print()
1548 if (j == job_list) in j_print()
1550 else if (j == job_list->next) in j_print()
1553 for (p = j->proc_list; p != NULL;) { in j_print()
1594 if (p == j->proc_list) in j_print()
1595 shf_fprintf(shf, "[%d] %c ", j->job, jobchar); in j_print()
1642 Job *j, *last_match; in j_lookup() local
1649 for (j = job_list; j != NULL; j = j->next) in j_lookup()
1650 if (j->last_proc && j->last_proc->pid == job) in j_lookup()
1651 return (j); in j_lookup()
1656 for (j = job_list; j != NULL; j = j->next) in j_lookup()
1657 if (j->pgrp && j->pgrp == job) in j_lookup()
1658 return (j); in j_lookup()
1684 for (j = job_list; j != NULL; j = j->next) in j_lookup()
1685 if (j->job == job) in j_lookup()
1686 return (j); in j_lookup()
1692 for (j = job_list; j != NULL; j = j->next) in j_lookup()
1693 for (p = j->proc_list; p != NULL; p = p->next) in j_lookup()
1700 last_match = j; in j_lookup()
1710 for (j = job_list; j != NULL; j = j->next) in j_lookup()
1711 if (strncmp(cp, j->proc_list->command, len) == 0) { in j_lookup()
1717 last_match = j; in j_lookup()
1741 Job *newj, *j; in new_job() local
1751 for (j = job_list; j && j->job != i; j = j->next) in new_job()
1753 if (j == NULL) in new_job()
1787 remove_job(Job *j, const char *where) in remove_job() argument
1794 while (curr && curr != j) { in remove_job()
1798 if (curr != j) { in remove_job()
1805 for (p = j->proc_list; p != NULL; ) { in remove_job()
1812 if ((j->flags & JF_ZOMBIE) && j->ppid == procpid) in remove_job()
1814 j->next = free_jobs; in remove_job()
1815 free_jobs = j; in remove_job()
1817 if (j == last_job) in remove_job()
1819 if (j == async_job) in remove_job()
1830 put_job(Job *j, int where) in put_job() argument
1837 while (curr && curr != j) { in put_job()
1841 if (curr == j) in put_job()
1846 j->next = job_list; in put_job()
1847 job_list = j; in put_job()
1856 j->next = curr; in put_job()
1857 *prev = j; in put_job()
1868 kill_job(Job *j, int sig) in kill_job() argument
1873 for (p = j->proc_list; p != NULL; p = p->next) in kill_job()