LoginSignup
3
2

More than 1 year has passed since last update.

【Linux】Ctrl+zで一時停止したプロセスの再開方法

Last updated at Posted at 2021-10-07

前置き

うっかりCtrl+zで停止してしまったプロセスを再開する方法を備忘録として残しておく。

今回はfileAを編集中に誤ってCtrl+zでプロセス一時停止してしまった場合を想定。

プロセスの停止

下記のとおりうっかりCtrl+zでプロセスを一時停止してしまった!

$ vim ./fileA

[1]+  停止                  vim ./fileA

ジョブIDを確認

jobsコマンドを使用して先ほど一時停止したジョブのIDを確認する。

$ jobs
[1]+  停止                  vim ./fileA

フォアグラウンドにする

fg <ジョブID>コマンドでジョブをフォアグラウンドにする。

ちなみにバックグラウンドにする場合はbg <ジョブID>だ。

$ fg 1

jobsのhelp

$ jobs --help
jobs: jobs [-lnprs] [jobspec ...] または jobs -x command [args]
    Display status of jobs.

    Lists the active jobs.  JOBSPEC restricts output to that job.
    Without options, the status of all active jobs is displayed.

    Options:
      -l        lists process IDs in addition to the normal information
      -n        lists only processes that have changed status since the last
                notification
      -p        lists process IDs only
      -r        restrict output to running jobs
      -s        restrict output to stopped jobs

    If -x is supplied, COMMAND is run after all job specifications that
    appear in ARGS have been replaced with the process ID of that job's
    process group leader.

    Exit Status:
    Returns success unless an invalid option is given or an error occurs.
    If -x is used, returns the exit status of COMMAND.

google翻訳

$ jobs --help
jobs:jobs [-lnprs] [jobspec ...]ジョブjobs-xコマンド[args]
     ジョブのステータスを表示します。

     アクティブなジョブを一覧表示します。 JOBSPECは、出力をそのジョブに制限します。
     オプションがない場合、アクティブなすべてのジョブのステータスが表示されます。

     オプション:
       -lは、通常の情報に加えてプロセスIDをリストします
       -nは、最後からステータスが変更されたプロセスのみを一覧表示します
                 通知
       -pはプロセスIDのみをリストします
       -r出力を実行中のジョブに制限します
       -s出力を停止したジョブに制限します

     -xが指定されている場合、COMMANDは、次のすべてのジョブ仕様の後に実行されます。
     ARGSに表示されるものは、そのジョブのプロセスIDに置き換えられました
     プロセスグループリーダー。

     終了ステータス:
     無効なオプションが指定されないか、エラーが発生しない限り、成功を返します。
     -xを使用すると、COMMANDの終了ステータスが返されます。

fgのhelp

$ fg --help
fg: fg [job_spec]
    ジョブをフォアグランドにします。

    JOB_SPEC で識別されたジョブをフォアグランドにして、現在のジョブにします。
    もし JOB_SPEC が存在しない場合、シェルが現在のレントジョブとして考えている
    ものが利用されます。


    終了ステータス:
    フォアグラウンドになったコマンドのステータスを返します。または、エラーが
    発生した時に失敗を返します。
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2