2021-05-11 02:29:21 +02:00
<!DOCTYPE HTML>
< html lang = "en" class = "sidebar-visible no-js light" >
< head >
<!-- Book generated using mdBook -->
< meta charset = "UTF-8" >
< title > Jobs & Signals - Zsh Manual< / title >
<!-- Custom HTML head -->
< meta content = "text/html; charset=utf-8" http-equiv = "Content-Type" >
< meta name = "description" content = "" >
< meta name = "viewport" content = "width=device-width, initial-scale=1" >
< meta name = "theme-color" content = "#ffffff" / >
< link rel = "icon" href = "favicon.svg" >
< link rel = "shortcut icon" href = "favicon.png" >
< link rel = "stylesheet" href = "css/variables.css" >
< link rel = "stylesheet" href = "css/general.css" >
< link rel = "stylesheet" href = "css/chrome.css" >
< link rel = "stylesheet" href = "css/print.css" media = "print" >
<!-- Fonts -->
< link rel = "stylesheet" href = "FontAwesome/css/font-awesome.css" >
< link rel = "stylesheet" href = "fonts/fonts.css" >
<!-- Highlight.js Stylesheets -->
< link rel = "stylesheet" href = "highlight.css" >
< link rel = "stylesheet" href = "tomorrow-night.css" >
< link rel = "stylesheet" href = "ayu-highlight.css" >
<!-- Custom theme stylesheets -->
< / head >
< body >
<!-- Provide site root to javascript -->
< script type = "text/javascript" >
var path_to_root = "";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
< / script >
<!-- Work around some values being stored in localStorage wrapped in quotes -->
< script type = "text/javascript" >
try {
var theme = localStorage.getItem('mdbook-theme');
var sidebar = localStorage.getItem('mdbook-sidebar');
if (theme.startsWith('"') & & theme.endsWith('"')) {
localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
}
if (sidebar.startsWith('"') & & sidebar.endsWith('"')) {
localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
}
} catch (e) { }
< / script >
<!-- Set the theme before any content is loaded, prevents flash -->
< script type = "text/javascript" >
var theme;
try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
if (theme === null || theme === undefined) { theme = default_theme; }
var html = document.querySelector('html');
html.classList.remove('no-js')
html.classList.remove('light')
html.classList.add(theme);
html.classList.add('js');
< / script >
<!-- Hide / unhide sidebar before it is displayed -->
< script type = "text/javascript" >
var html = document.querySelector('html');
var sidebar = 'hidden';
if (document.body.clientWidth >= 1080) {
try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
sidebar = sidebar || 'visible';
}
html.classList.remove('sidebar-visible');
html.classList.add("sidebar-" + sidebar);
< / script >
< nav id = "sidebar" class = "sidebar" aria-label = "Table of contents" >
< div class = "sidebar-scrollbox" >
2022-08-24 15:22:41 +02:00
< ol class = "chapter" > < li class = "chapter-item expanded " > < a href = "The-Z-Shell-Manual.html" > < strong aria-hidden = "true" > 1.< / strong > The Z Shell Manual< / a > < / li > < li class = "chapter-item expanded " > < a href = "Introduction.html" > < strong aria-hidden = "true" > 2.< / strong > Introduction< / a > < / li > < li class = "chapter-item expanded " > < a href = "Roadmap.html" > < strong aria-hidden = "true" > 3.< / strong > Roadmap< / a > < / li > < li class = "chapter-item expanded " > < a href = "Invocation.html" > < strong aria-hidden = "true" > 4.< / strong > Invocation< / a > < / li > < li class = "chapter-item expanded " > < a href = "Files.html" > < strong aria-hidden = "true" > 5.< / strong > Files< / a > < / li > < li class = "chapter-item expanded " > < a href = "Shell-Grammar.html" > < strong aria-hidden = "true" > 6.< / strong > Shell Grammar< / a > < / li > < li class = "chapter-item expanded " > < a href = "Redirection.html" > < strong aria-hidden = "true" > 7.< / strong > Redirection< / a > < / li > < li class = "chapter-item expanded " > < a href = "Command-Execution.html" > < strong aria-hidden = "true" > 8.< / strong > Command Execution< / a > < / li > < li class = "chapter-item expanded " > < a href = "Functions.html" > < strong aria-hidden = "true" > 9.< / strong > Functions< / a > < / li > < li class = "chapter-item expanded " > < a href = "Jobs-&-Signals.html" class = "active" > < strong aria-hidden = "true" > 10.< / strong > Jobs & Signals< / a > < / li > < li class = "chapter-item expanded " > < a href = "Arithmetic-Evaluation.html" > < strong aria-hidden = "true" > 11.< / strong > Arithmetic Evaluation< / a > < / li > < li class = "chapter-item expanded " > < a href = "Conditional-Expressions.html" > < strong aria-hidden = "true" > 12.< / strong > Conditional Expressions< / a > < / li > < li class = "chapter-item expanded " > < a href = "Prompt-Expansion.html" > < strong aria-hidden = "true" > 13.< / strong > Prompt Expansion< / a > < / li > < li class = "chapter-item expanded " > < a href = "Expansion.html" > < strong aria-hidden = "true" > 14.< / strong > Expansion< / a > < / li > < li class = "chapter-item expanded " > < a href = "Parameters.html" > < strong aria-hidden = "true" > 15.< / strong > Parameters< / a > < / li > < li class = "chapter-item expanded " > < a href = "Options.html" > < strong aria-hidden = "true" > 16.< / strong > Options< / a > < / li > < li class = "chapter-item expanded " > < a href = "Shell-Builtin-Commands.html" > < strong aria-hidden = "true" > 17.< / strong > Shell Builtin Commands< / a > < / li > < li class = "chapter-item expanded " > < a href = "Zsh-Line-Editor.html" > < strong aria-hidden = "true" > 18.< / strong > Zsh Line Editor< / a > < / li > < li class = "chapter-item expanded " > < a href = "Completion-Widgets.html" > < strong aria-hidden = "true" > 19.< / strong > Completion Widgets< / a > < / li > < li class = "chapter-item expanded " > < a href = "Completion-System.html" > < strong aria-hidden = "true" > 20.< / strong > Completion System< / a > < / li > < li class = "chapter-item expanded " > < a href = "Completion-Using-compctl.html" > < strong aria-hidden = "true" > 21.< / strong > Completion Using compctl< / a > < / li > < li class = "chapter-item expanded " > < a href = "Zsh-Modules.html" > < strong aria-hidden = "true" > 22.< / strong > Zsh Modules< / a > < / li > < li class = "chapter-item expanded " > < a href = "Calendar-Function-System.html" > < strong aria-hidden = "true" > 23.< / strong > Calendar Function System< / a > < / li > < li class = "chapter-item expanded " > < a href = "TCP-Function-System.html" > < strong aria-hidden = "true" > 24.< / strong > TCP Function System< / a > < / li > < li class = "chapter-item expanded " > < a href = "Zftp-Function-System.html" > < strong aria-hidden = "true" > 25.< / strong > Zftp Function System< / a > < / li > < li class = "chapter-item expanded " > < a href = "User-Contributions.html" > < strong aria-hidden = "true" > 26.< / strong > User Contributions< / a > < / li > < / ol >
2021-05-11 02:29:21 +02:00
< / div >
< div id = "sidebar-resize-handle" class = "sidebar-resize-handle" > < / div >
< / nav >
< div id = "page-wrapper" class = "page-wrapper" >
< div class = "page" >
2022-08-24 15:22:41 +02:00
< div id = "menu-bar-hover-placeholder" > < / div >
2021-05-11 02:29:21 +02:00
< div id = "menu-bar" class = "menu-bar sticky bordered" >
< div class = "left-buttons" >
< button id = "sidebar-toggle" class = "icon-button" type = "button" title = "Toggle Table of Contents" aria-label = "Toggle Table of Contents" aria-controls = "sidebar" >
< i class = "fa fa-bars" > < / i >
< / button >
< button id = "theme-toggle" class = "icon-button" type = "button" title = "Change theme" aria-label = "Change theme" aria-haspopup = "true" aria-expanded = "false" aria-controls = "theme-list" >
< i class = "fa fa-paint-brush" > < / i >
< / button >
< ul id = "theme-list" class = "theme-popup" aria-label = "Themes" role = "menu" >
< li role = "none" > < button role = "menuitem" class = "theme" id = "light" > Light (default)< / button > < / li >
< li role = "none" > < button role = "menuitem" class = "theme" id = "rust" > Rust< / button > < / li >
< li role = "none" > < button role = "menuitem" class = "theme" id = "coal" > Coal< / button > < / li >
< li role = "none" > < button role = "menuitem" class = "theme" id = "navy" > Navy< / button > < / li >
< li role = "none" > < button role = "menuitem" class = "theme" id = "ayu" > Ayu< / button > < / li >
< / ul >
< button id = "search-toggle" class = "icon-button" type = "button" title = "Search. (Shortkey: s)" aria-label = "Toggle Searchbar" aria-expanded = "false" aria-keyshortcuts = "S" aria-controls = "searchbar" >
< i class = "fa fa-search" > < / i >
< / button >
< / div >
< h1 class = "menu-title" > Zsh Manual< / h1 >
< div class = "right-buttons" >
< a href = "print.html" title = "Print this book" aria-label = "Print this book" >
< i id = "print-button" class = "fa fa-print" > < / i >
< / a >
2021-05-17 17:00:52 +02:00
2021-05-11 02:29:21 +02:00
< / div >
< / div >
< div id = "search-wrapper" class = "hidden" >
< form id = "searchbar-outer" class = "searchbar-outer" >
2021-05-17 17:00:52 +02:00
< input type = "search" id = "searchbar" name = "searchbar" placeholder = "Search this book ..." aria-controls = "searchresults-outer" aria-describedby = "searchresults-header" >
2021-05-11 02:29:21 +02:00
< / form >
< div id = "searchresults-outer" class = "searchresults-outer hidden" >
< div id = "searchresults-header" class = "searchresults-header" > < / div >
< ul id = "searchresults" >
< / ul >
< / div >
< / div >
<!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
< script type = "text/javascript" >
document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
});
< / script >
< div id = "content" class = "content" >
< main >
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE - RUN doctoc TO UPDATE -->
< p > < strong > Table of Contents< / strong > < em > generated with < a href = "https://github.com/thlorenz/doctoc" > DocToc< / a > < / em > < / p >
< ul >
< li > < a href = "#10-jobs--signals" > 10 Jobs & Signals< / a >
< ul >
< li > < a href = "#101-jobs" > 10.1 Jobs< / a > < / li >
< li > < a href = "#102-signals" > 10.2 Signals< / a > < / li >
< / ul >
< / li >
< / ul >
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2022-08-24 15:22:41 +02:00
< p > < span id = "Jobs-_0026-Signals" > < / span > < span
id="Jobs-_0026-Signals-1">< / span > < / p >
2021-05-11 02:29:21 +02:00
< h1 id = "10-jobs--signals" > < a class = "header" href = "#10-jobs--signals" > 10 Jobs & Signals< / a > < / h1 >
< hr / >
< p > < span id = "Jobs" > < / span > < / p >
< h2 id = "101-jobs" > < a class = "header" href = "#101-jobs" > 10.1 Jobs< / a > < / h2 >
2022-08-24 15:22:41 +02:00
< p > < span id = "index-jobs" > < / span > < span
id="index-MONITOR_002c-use-of">< / span > < / p >
< p > If the MONITOR option is set, an interactive shell associates a < em > job< / em >
2021-05-11 02:29:21 +02:00
with each pipeline. command, and assigns them small integer numbers.
2022-08-24 15:22:41 +02:00
When a job is started asynchronously with ‘ & ’ , the shell prints a line
2021-05-11 02:29:21 +02:00
to standard error which looks like:< / p >
< div class = "example" >
2022-08-24 15:22:41 +02:00
< pre > < code class = "language-zsh" > [1] 1234
2021-05-11 02:29:21 +02:00
< / code > < / pre >
< / div >
< p > indicating that the job which was started asynchronously was job number
1 and had one (top-level) process, whose process ID was 1234.< / p >
2022-08-24 15:22:41 +02:00
< p > If a job is started with ‘ & |’ or ‘ & !’ , then that job is immediately
2021-05-11 02:29:21 +02:00
disowned. After startup, it to the job control features described here.< / p >
< p > If you are running a job and wish to do something else you may hit the
2022-08-24 15:22:41 +02:00
key ^Z (control-Z) which sends a TSTP signal to the current job: this
key may be redefined by the susp option of the external stty command.
< span id = "index-jobs_002c-suspending" > < / span > < span
id="index-suspending-jobs">< / span > The shell will then normally indicate
that the job has been ‘ suspended’ , and print another prompt. You can
then manipulate the state of this job, < span
id="index-bg_002c-use-of">< / span > putting it in the background with the
bg command, or run some other commands and then eventually bring the job
back into the foreground with < span id = "index-fg_002c-use-of" > < / span >
the foreground command fg. A ^Z takes effect immediately and is like an
interrupt in that pending output and unread input are discarded when it
is typed.< / p >
2021-05-11 02:29:21 +02:00
< p > A job being run in the background will suspend if it tries to read from
the terminal.< / p >
< p > Note that if the job running in the foreground is a shell function, then
suspending it will have the effect of causing the shell to fork. This is
necessary to separate the function’ s state from that of the parent shell
performing the job control, so that the latter can return to the command
2022-08-24 15:22:41 +02:00
line prompt. As a result, even if fg is used to continue the job the
2021-05-11 02:29:21 +02:00
function will no longer be part of the parent shell, and any variables
set by the function will not be visible in the parent shell. Thus the
behaviour is different from the case where the function was never
suspended. Zsh is different from many other shells in this regard.< / p >
2022-08-24 15:22:41 +02:00
< p > One additional side effect is that use of disown with a job created by
2021-05-11 02:29:21 +02:00
suspending shell code in this fashion is delayed: the job can only be
disowned once any process started from the parent shell has terminated.
At that point, the disowned job disappears silently from the job list.< / p >
< p > The same behaviour is found when the shell is executing code as the
2022-08-24 15:22:41 +02:00
right hand side of a pipeline or any complex shell construct such as if,
for, etc., in order that the entire block of code can be managed as a
single job. < span id = "index-background-jobs_002c-I_002fO" > < / span > < span
id="index-jobs_002c-background_002c-I_002fO">< / span > Background jobs are
normally allowed to produce output, but this can be disabled by giving
the command ‘ stty tostop’ . If you set this tty option, then background
jobs will suspend when they try to produce output like they do when they
try to read input.< / p >
< p > When a command is suspended and continued later with the fg or wait
2021-05-11 02:29:21 +02:00
builtins, zsh restores tty modes that were in effect when it was
suspended. This (intentionally) does not apply if the command is
2022-08-24 15:22:41 +02:00
continued via ‘ kill -CONT’ , nor when it is continued with bg.< / p >
< p > < span id = "index-jobs_002c-referring-to" > < / span > < span
id="index-referring-to-jobs">< / span > < / p >
2021-05-11 02:29:21 +02:00
< p > There are several ways to refer to jobs in the shell. A job can be
referred to by the process ID of any process of the job or by one of the
following:< / p >
2022-08-24 15:22:41 +02:00
< p > %< code > number< / code > < br / >
2021-05-11 02:29:21 +02:00
The job with the given number.< / p >
2022-08-24 15:22:41 +02:00
< p > %< code > string< / code > < br / >
2021-05-11 02:29:21 +02:00
The last job whose command line begins with < code > string< / code > .< / p >
2022-08-24 15:22:41 +02:00
< p > %?< code > string< / code > < br / >
2021-05-11 02:29:21 +02:00
The last job whose command line contains < code > string< / code > .< / p >
2022-08-24 15:22:41 +02:00
< p > %%< br / >
2021-05-11 02:29:21 +02:00
Current job.< / p >
2022-08-24 15:22:41 +02:00
< p > %+< br / >
Equivalent to ‘ %%’ .< / p >
< p > %-< br / >
2021-05-11 02:29:21 +02:00
Previous job.< / p >
2022-08-24 15:22:41 +02:00
< p > The shell learns immediately whenever a process changes state. < span
id="index-NOTIFY_002c-use-of">< / span > It normally informs you whenever a
job becomes blocked so that no further progress is possible. If the
NOTIFY option is not set, it waits until just before it prints a prompt
before it informs you. All such notifications are sent directly to the
terminal, not to the standard output or standard error.< / p >
2021-05-11 02:29:21 +02:00
< p > When the monitor mode is on, each background job that completes triggers
2022-08-24 15:22:41 +02:00
any trap set for CHLD.< / p >
2021-05-11 02:29:21 +02:00
< p > When you try to leave the shell while jobs are running or suspended, you
will be warned that ‘ You have suspended (running) jobs’ . You may use the
2022-08-24 15:22:41 +02:00
jobs command to see what they are. If you do this or immediately try to
exit again, the shell will not warn you a second time; the suspended
jobs will be terminated, and the running jobs will be sent a SIGHUP
signal, if the HUP option is set. < span
id="index-HUP_002c-use-of">< / span > < / p >
< p > < span id = "index-jobs_002c-disowning" > < / span > < span
id="index-disowning-jobs">< / span > < span
id="index-disown_002c-use-of">< / span > < / p >
2021-05-11 02:29:21 +02:00
< p > To avoid having the shell terminate the running jobs, either use the
2022-08-24 15:22:41 +02:00
nohup(1) command or the disown builtin.< / p >
2021-05-11 02:29:21 +02:00
< hr / >
< p > < span id = "Signals" > < / span > < / p >
< h2 id = "102-signals" > < a class = "header" href = "#102-signals" > 10.2 Signals< / a > < / h2 >
2022-08-24 15:22:41 +02:00
< p > The INT and QUIT signals for an invoked command are ignored if the
command is followed by ‘ & ’ and the MONITOR option is not active. The
shell itself always ignores the QUIT signal. Otherwise, signals have the
values inherited by the shell from its parent (but see the TRAP< code > NAL< / code >
special functions in < a href = "Functions.html#Functions" > Functions< / a > ).< / p >
< p > < span id = "index-exiting-shell_002c-and-asynchronous-jobs" > < / span > < span
id="index-asynchronous-jobs_002c-and-exiting-shell">< / span > < span
id="index-jobs_002c-asynchronous_002c-and-exiting-shell">< / span > < / p >
2021-05-11 02:29:21 +02:00
< p > Certain jobs are run asynchronously by the shell other than those
explicitly put into the background; even in cases where the shell would
2022-08-24 15:22:41 +02:00
usually wait for such jobs, an explicit exit command or exit due to the
option ERR_EXIT will cause the shell to exit without waiting. Examples
of such asynchronous jobs are process substitution, see < a href = "Expansion.html#Process-Substitution" > Process
Substitution< / a > , and the handler
processes for multios, see the section < em > Multios< / em > in
2021-05-11 02:29:21 +02:00
< a href = "Redirection.html#Redirection" > Redirection< / a > .< / p >
< hr / >
2022-08-24 15:22:41 +02:00
< p > This document was generated on < em > May 14, 2022< / em > using < a href = "http://www.nongnu.org/texi2html/" > < em > texi2html
5.0< / em > < / a > .< br / >
Zsh version 5.9, released on May 14, 2022.< / p >
2021-05-11 02:29:21 +02:00
< / main >
< nav class = "nav-wrapper" aria-label = "Page navigation" >
<!-- Mobile navigation buttons -->
< a rel = "prev" href = "Functions.html" class = "mobile-nav-chapters previous" title = "Previous chapter" aria-label = "Previous chapter" aria-keyshortcuts = "Left" >
< i class = "fa fa-angle-left" > < / i >
< / a >
< a rel = "next" href = "Arithmetic-Evaluation.html" class = "mobile-nav-chapters next" title = "Next chapter" aria-label = "Next chapter" aria-keyshortcuts = "Right" >
< i class = "fa fa-angle-right" > < / i >
< / a >
< div style = "clear: both" > < / div >
< / nav >
< / div >
< / div >
< nav class = "nav-wide-wrapper" aria-label = "Page navigation" >
< a rel = "prev" href = "Functions.html" class = "nav-chapters previous" title = "Previous chapter" aria-label = "Previous chapter" aria-keyshortcuts = "Left" >
< i class = "fa fa-angle-left" > < / i >
< / a >
< a rel = "next" href = "Arithmetic-Evaluation.html" class = "nav-chapters next" title = "Next chapter" aria-label = "Next chapter" aria-keyshortcuts = "Right" >
< i class = "fa fa-angle-right" > < / i >
< / a >
< / nav >
< / div >
< script type = "text/javascript" >
window.playground_copyable = true;
< / script >
< script src = "elasticlunr.min.js" type = "text/javascript" charset = "utf-8" > < / script >
< script src = "mark.min.js" type = "text/javascript" charset = "utf-8" > < / script >
< script src = "searcher.js" type = "text/javascript" charset = "utf-8" > < / script >
< script src = "clipboard.min.js" type = "text/javascript" charset = "utf-8" > < / script >
< script src = "highlight.js" type = "text/javascript" charset = "utf-8" > < / script >
< script src = "book.js" type = "text/javascript" charset = "utf-8" > < / script >
<!-- Custom JS scripts -->
< / body >
< / html >