Knowledge

Job control (Unix)

Source 📝

353: 297: 128:
However, sometimes the user will wish to carry out a task while using the terminal for another purpose. A task that is running but is not receiving input from the terminal is said to be running "in the background", while the single task that is receiving input from the terminal is "in the
140:
maps the (shell) concept of a single shell command to the (operating system) concept of the possibly many processes that the command entails. Multi-process tasks come about because processes may create additional child processes, and a single shell command may consist of a
551:(for output) signal. These signals stop the process by default, but they may also be handled in other ways. Shells often override the default stop action of SIGTTOU so that background processes deliver their output to the controlling terminal by default. 254:
Job control and job IDs are typically only used in interactive use, where they simplify referring to process groups; in scripting PGIDs are used instead, as they are more precise and robust, and indeed job control is disabled by default in bash scripts.
485:) to the process group. By default, SIGTSTP causes processes receiving it to stop, and control is returned to the shell. However, a process can register a signal handler for or ignore SIGTSTP. A process can also be paused with the "stop" signal ( 112:
shell). Most tasks (directory listing, editing files, etc.) can easily be accomplished by letting the program take control of the terminal and returning control to the shell when the program exits – formally, by attaching to
450:
command can be used to remove jobs from the job table, so that when the session ends the child process groups are not sent SIGHUP, nor does the shell wait for them to terminate. They thus become
129:
foreground". Job control is a facility developed to make this possible, by allowing the user to start processes in the background, send already running processes into the background, bring
564:) can signal jobs by job ID as well as by process group ID – sending a signal to a job sends it to the whole process group, and jobs specified by a job ID should be killed by prefixing 64:. Basic job control features are the suspending, resuming, or terminating of all processes in the job/process group; more advanced features can be performed by sending 536:) to the command line; its output is directed to the terminal (potentially interleaved with other programs' output), but it cannot read from the terminal input. 145:
of multiple communicating processes. For example, a command to select lines containing the text "title", sort these alphabetically, and display the result in a
117:
to the shell, which reads or writes from the terminal, and catching signals sent from the keyboard, like the termination signal resulting from pressing
248:. In informal usage the number may be referred to as the "job number" or "job ID", and Bash documentation refers to the (%-prefixed) job ID as the 181:. Job control allows the shell to control these related processes as one entity, and when a user issues the appropriate key combination (usually 617:
A job ID is an abstract reference by the shell to a resource (a process group) managed externally, by the operating system, hence is a handle.
425:
command will list the background jobs existing in the job table, along with their job number and job state (stopped or running). When a
786: 661: 204:
A set of processes, comprising a shell pipeline, and any processes descended from it, that are all in the same process group.
374: 769: 691: 638: 400: 331:
The POSIX standard specifies two commands for resuming suspended jobs in the background and foreground, respectively
650: 382: 454:, and may be terminated by the operating system, though more often this is used so the processes are adopted by 378: 31: 109: 608:
Here "task" is a non-technical term for "some activity", while "process" and "job" are technical terms.
572:
can send any signal to a job; however, if the intent is to rid the system of the processes the signals
459: 755: 730: 714: 17: 724: 708: 363: 367: 311: 279:, developed at Bell Labs, adopted it and it was later incorporated into the SVR4 version of the 751: 540: 467: 417:. Recall that a job corresponds to a process group, which consists of all the members of a 8: 492:
A job running in the foreground can be interrupted by typing the interruption character (
196:, and the job is the shell's internal representation of such a group. This is defined in 310:
Please expand the section to include this information. Further details may exist on the
478: 209: 130: 65: 765: 687: 680: 529: 528:
signal to the process, which causes the operating system to resume its execution. In
101: 97: 73: 114: 77: 45: 750: 418: 142: 69: 473:
A job running in the foreground can be stopped by typing the suspend character (
441:
to all jobs, and waits for the process groups to end before terminating itself.
734: 718: 556: 498: 451: 146: 104:), a user will initially only have a single process running, their interactive 803: 797: 511: 445: 426: 225: 193: 61: 60:, especially interactively, where a "job" is a shell's representation for a 30:
This article is about job control on Unix system. For the general term, see
759: 521: 502:), which defaults to terminating the process, though it can be overridden. 280: 532:, a program can be started as a background job by appending an ampersand ( 458:(the kernel sets their parent process to init) and continue executing as 176: 105: 57: 516: 507: 276: 93: 68:
to the job. Job control is of particular interest in Unix due to its
42: 352: 673: 589: 577: 573: 264: 539:
A background process that attempts to read from or write to its
339:. These were modeled after the Korn shell job control commands. 296: 76:
generally, which is frequently applied to sequential execution (
493: 474: 438: 430: 761:
The Design and Implementation of the FreeBSD Operating System
463: 462:. Alternatives to prevent jobs from being terminated include 268: 245: 197: 455: 244:
identifies the current job. Other job IDs are specified by
167: 89: 38: 505:
A stopped job can be resumed as a background job with the
756:"FreeBSD Process Management: Process Groups and Sessions" 272: 133:
into the foreground, and suspend or terminate processes.
677: 192:
Jobs are managed by the operating system as a single
679: 189:), the entire group of processes gets suspended. 795: 580:(the default) are probably the most applicable. 413:Typically, the shell keeps a list of jobs in a 165:This creates at least three processes: one for 271:in Austria, making use of features of the 4.1 729: – Shell and Utilities Reference, 713: – Shell and Utilities Reference, 228:to refer to the job. Job IDs begin with the 381:. Unsourced material may be challenged and 754:and George V. Neville-Neil (2004-08-02). 401:Learn how and when to remove this message 283:, and exists in most modern Unix shells. 263:Job control was first implemented in the 433:(exits the shell, which terminates the 14: 796: 678:Anderson, Gail; Paul Anderson (1986). 520:. In either case, the shell redirects 496:). This sends the "interrupt" signal ( 489:), which cannot be caught or ignored. 379:adding citations to reliable sources 346: 290: 477:). This sends the "terminal stop" 72:, and should be distinguished from 24: 744: 437:process), the shell process sends 115:standard input and standard output 25: 815: 779: 651:Section 3.203, Job Control Job ID 342: 514:, or as the foreground job with 351: 295: 686:. Prentice-Hall. p. xvii. 554:In Bash-compatible shells, the 27:Control of jobs by a Unix shell 700: 666: 655: 643: 631: 611: 602: 208:A job can be referred to by a 13: 1: 731:The Single UNIX Specification 715:The Single UNIX Specification 624: 524:appropriately, and sends the 682:The UNIX C Shell Field Guide 7: 583: 421:and their descendants. The 286: 83: 10: 820: 258: 29: 595: 151: 108:(it may or may not be a 96:operating systems via a 32:job control (computing) 752:Marshall Kirk McKusick 662:7.1 Job Control Basics 649:IEEE Std 1003.1-2001, 637:IEEE Std 1003.1-2001, 306:is missing information 206: 788:Bash Reference Manual 267:by Jim Kulp, then at 202: 153:greptitlesomefile.txt 52:refers to control of 541:controlling terminal 468:terminal multiplexer 375:improve this section 131:background processes 429:ends when the user 224:, which is used by 764:. Addison Wesley. 639:Section 3.201, Job 214:job control job ID 733:, Version 4 from 717:, Version 4 from 411: 410: 403: 329: 328: 136:The concept of a 102:terminal emulator 46:operating systems 16:(Redirected from 811: 775: 738: 728: 727: 712: 711: 704: 698: 697: 685: 670: 664: 659: 653: 647: 641: 635: 618: 615: 609: 606: 571: 567: 563: 559: 535: 519: 510: 452:orphan processes 448: 424: 406: 399: 395: 392: 386: 355: 347: 338: 334: 324: 321: 315: 299: 291: 243: 235: 231: 222: 221: 179: 174: 170: 160: 156: 78:batch processing 21: 819: 818: 814: 813: 812: 810: 809: 808: 794: 793: 785:"Job Control", 782: 772: 747: 745:Further reading 742: 741: 723: 722: 707: 706: 705: 701: 694: 671: 667: 660: 656: 648: 644: 636: 632: 627: 622: 621: 616: 612: 607: 603: 598: 586: 569: 565: 561: 555: 547:(for input) or 533: 515: 506: 446: 422: 407: 396: 390: 387: 372: 356: 345: 336: 332: 325: 319: 316: 309: 300: 289: 261: 241: 236:identifies job 233: 229: 219: 218: 188: 184: 177: 172: 166: 163: 162: 158: 154: 124: 120: 86: 70:multiprocessing 35: 28: 23: 22: 15: 12: 11: 5: 817: 807: 806: 792: 791: 781: 780:External links 778: 777: 776: 770: 746: 743: 740: 739: 735:The Open Group 719:The Open Group 699: 692: 665: 654: 642: 629: 628: 626: 623: 620: 619: 610: 600: 599: 597: 594: 593: 592: 585: 582: 435:session leader 409: 408: 359: 357: 350: 344: 343:Implementation 341: 327: 326: 303: 301: 294: 288: 285: 260: 257: 226:shell builtins 186: 182: 175:, and one for 152: 122: 118: 85: 82: 26: 9: 6: 4: 3: 2: 816: 805: 802: 801: 799: 790: 789: 784: 783: 773: 771:0-201-70245-2 767: 763: 762: 757: 753: 749: 748: 736: 732: 726: 720: 716: 710: 703: 695: 693:0-13-937468-X 689: 684: 683: 675: 669: 663: 658: 652: 646: 640: 634: 630: 614: 605: 601: 591: 588: 587: 581: 579: 575: 560:builtin (not 558: 552: 550: 546: 542: 537: 531: 527: 523: 518: 513: 509: 503: 501: 500: 495: 490: 488: 484: 480: 476: 471: 469: 465: 461: 457: 453: 449: 442: 440: 436: 432: 428: 420: 416: 405: 402: 394: 391:February 2020 384: 380: 376: 370: 369: 365: 360:This section 358: 354: 349: 348: 340: 323: 313: 307: 304:This section 302: 298: 293: 292: 284: 282: 278: 274: 270: 266: 256: 252: 251: 247: 239: 227: 223: 215: 211: 205: 201: 199: 195: 194:process group 190: 180: 169: 150: 148: 144: 139: 134: 132: 126: 116: 111: 107: 103: 99: 95: 91: 81: 79: 75: 71: 67: 63: 62:process group 59: 55: 51: 47: 44: 40: 33: 19: 787: 760: 702: 681: 672:Foreword by 668: 657: 645: 633: 613: 604: 553: 548: 544: 538: 525: 504: 497: 491: 486: 482: 472: 466:and using a 443: 434: 414: 412: 397: 388: 373:Please help 361: 330: 317: 305: 281:Bourne shell 275:kernel. The 262: 253: 249: 237: 217: 213: 207: 203: 191: 164: 137: 135: 127: 87: 53: 49: 36: 308:about wait. 232:character; 212:called the 88:When using 74:job control 50:job control 625:References 543:is sent a 320:April 2021 216:or simply 171:, one for 562:/bin/kill 415:job table 362:does not 312:talk page 277:KornShell 94:Unix-like 43:Unix-like 18:Bg (Unix) 798:Category 674:Bill Joy 584:See also 431:logs out 419:pipeline 287:Commands 250:jobspec. 240:, while 143:pipeline 98:terminal 84:Overview 590:C shell 578:SIGTERM 574:SIGKILL 549:SIGTTOU 545:SIGTTIN 526:SIGCONT 512:builtin 487:SIGSTOP 483:SIGTSTP 460:daemons 427:session 383:removed 368:sources 265:C shell 259:History 183:Control 119:Control 66:signals 768:  690:  499:SIGINT 494:Ctrl-C 479:signal 475:Ctrl-Z 447:disown 439:SIGHUP 220:job ID 210:handle 596:Notes 534:& 464:nohup 269:IIASA 246:POSIX 198:POSIX 161:less 147:pager 110:login 106:shell 58:shell 56:by a 804:Unix 766:ISBN 688:ISBN 576:and 570:kill 557:kill 530:Bash 456:init 444:The 423:jobs 366:any 364:cite 335:and 200:as: 178:less 173:sort 168:grep 157:sort 100:(or 90:Unix 54:jobs 41:and 39:Unix 676:in 522:I/O 377:by 273:BSD 138:job 92:or 80:). 37:In 800:: 758:. 725:fg 721:; 709:bg 568:. 517:fg 508:bg 470:. 337:fg 333:bg 242:%% 234:%n 149:. 125:. 48:, 774:. 737:. 696:. 566:% 481:( 404:) 398:( 393:) 389:( 385:. 371:. 322:) 318:( 314:. 238:n 230:% 187:Z 185:+ 159:| 155:| 123:C 121:+ 34:. 20:)

Index

Bg (Unix)
job control (computing)
Unix
Unix-like
operating systems
shell
process group
signals
multiprocessing
job control
batch processing
Unix
Unix-like
terminal
terminal emulator
shell
login
standard input and standard output
background processes
pipeline
pager
grep
less
process group
POSIX
handle
shell builtins
POSIX
C shell
IIASA

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.