官术网_书友最值得收藏!

  • Bash Quick Start Guide
  • Tom Ryder
  • 198字
  • 2021-07-23 16:58:58

Running a command in the background

There are some situations in which you might want to continue running other commands as you wait for another one to complete, to run more than one job in parallel. You can arrange for a command to run in the background by ending it with a single ampersand (&) control operator.

You can try this out by issuing a sleep command in the background. The sleep built-in Bash command accepts a number of seconds to wait as an argument. If you enter such a command without the &, Bash won't accept further commands until the command exits:

$ sleep 10
# Ten seconds pass... $

However, if you add the & terminator to start the job in the background, the behavior is different: you get a job control number and a process ID, and you are returned immediately to your prompt:

$ sleep 10 &
[1] 435
$

You can continue running other commands as normal while this job is running in the background. After the 10 seconds are up, the next time the prompt appears, it will also print output telling you the job has completed:

[1]+  Done                    sleep 10
$
主站蜘蛛池模板: 荆门市| 通榆县| 胶州市| 富阳市| 浠水县| 锡林郭勒盟| 枣强县| 民权县| 新闻| 武宣县| 客服| 宁都县| 铜川市| 玛曲县| 页游| 留坝县| 哈尔滨市| 额敏县| 大理市| 肥乡县| 恩施市| 南丹县| 和田市| 白山市| 蒙城县| 马鞍山市| 南昌县| 贵州省| 隆尧县| 广河县| 木里| 乌什县| 从江县| 建阳市| 额尔古纳市| 平阳县| 肥乡县| 浦县| 广东省| 阿鲁科尔沁旗| 张家川|