Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Bash (Unix shell)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Process Management (a.k.a., "Job control") === The Bash shell has two modes of execution for commands: batch (asynchronous), and concurrent (synchronous). To execute commands in batch mode (i.e., in sequence) they must be separated by the character ";", or on separate lines: <syntaxhighlight lang="bash"> command1; command2 command3 </syntaxhighlight> In this example, when command1 is finished, command2 is executed, and when command2 has completed, command3 will execute. A [[Background process|background execution]] of command1 can occur using (symbol &) at the end of an execution command, and process will be executed in background while immediately returning control to the shell and allowing continued execution of commands. <syntaxhighlight lang="bash">command1 &</syntaxhighlight> Or to have a concurrent execution of command1 and command2, they must be executed in the Bash shell in the following way: <syntaxhighlight lang="bash"> command1 & command2 </syntaxhighlight> In this case command1 is executed in the background ''&'' symbol, returning immediately control to the shell that executes command2 in the foreground. A process can be stopped and control returned to bash by typing {{Key press|Ctrl|z}} while the process is running in the foreground.<ref>{{Cite web |title=Bash Reference Manual |url=https://www.gnu.org/software/bash/manual/bash.html#index-background |url-status=live |archive-url=https://web.archive.org/web/20180315115230/http://www.gnu.org/software/bash/manual/bash.html#index-background |archive-date=March 15, 2018 |access-date=March 27, 2018 |publisher=[[GNU Project]] }}</ref> A list of all processes, both in the background and stopped, can be achieved by running <code>jobs</code>: <syntaxhighlight lang="console"> $ jobs [1]- Running command1 & [2]+ Stopped command2 </syntaxhighlight> In the output, the number in brackets refers to the job id. The plus sign signifies the default process for <code>bg</code> and <code>fg</code>. The text "Running" and "Stopped" refer to the [[process state]]. The last string is the command that started the process. The state of a process can be changed using various commands. The <code>fg</code> command brings a process to the foreground, while <code>bg</code> sets a stopped process running in the background. <code>bg</code> and <code>fg</code> can take a job id as their first argument, to specify the process to act on. Without one, they use the default process, identified by a plus sign in the output of <code>jobs</code>. The <code>[[Kill (command)|kill]]</code> command can be used to end a process prematurely, by sending it a [[Signal (IPC)|signal]]. The job id must be specified after a percent sign: <syntaxhighlight lang="bash"> kill %1 </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)