

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 构建环境中的后台任务
<a name="build-env-ref-background-tasks"></a>

您可以在构建环境中运行后台任务。要执行此操作，请在您的 buildspec 中，使用 `nohup` 命令将命令作为后台中的任务运行，即使构建过程已退出 Shell 也是如此。使用 **disown** 命令强制停止正在运行的后台任务。

**示例：**
+ 启动后台进程并等待其稍后完成：

  ```
  |
  nohup sleep 30 & echo $! > pidfile
  …
  wait $(cat pidfile)
  ```
+  启动后台进程，但不等待其完成：

  ```
  |
  nohup sleep 30 & disown $!
  ```
+  启动后台进程并稍后将其终止：

  ```
  |
  nohup sleep 30 & echo $! > pidfile
  …
  kill $(cat pidfile)
  ```