bg  ジョブ バックグラウンド 実行 切り替え

 構文  
bg [%jobsid]  

 オプション  
%jobsid

バックグラウンドで実行するコマンドの
 ジョブ番号を指定する

ジョブ番号はjobsコマンドにて確認できる。

[takuan@localhost ~]$ jobs
[1]-  Stopped                 vim tmp.txt
[2]+  Stopped                 find / -name *.txt
 

 説明  
ジョブをバックグラウンドで実行するコマンドです。
パラメータを省略した場合は
カレントジョブ(+のついたジョブ)を実行します。


[takuan@localhost ~]$ find / -name *.txt
find: /var/cache/mod_proxy: 許可がありません
省略・・・

^Z
[1]+  Stopped                 find / -name *.txt
[takuan@localhost ~]$ jobs
[1]+  Stopped                 find / -name *.txt
[takuan@localhost ~]$ bg
[1]+ find / -name *.txt &



find: /etc/lvm/archive: 許可がありません
find: /etc/cups/ssl: 許可がありません

[1]+  Exit 1                  find / -name *.txt
[takuan@localhost ~]$

       bg [jobspec ...]
              Resume each suspended job jobspec in the background, as if  it  had
              been started with &.  If jobspec is not present, the shell's notion
              of the current job is used.  bg jobspec returns 0 unless  run  when
              job  control is disabled or, when run with job control enabled, any
              specified jobspec was not found or was started without job control.

 使用例  



[takuan@localhost ~]$ touch tmp.txt

→tmp.txtの作成


[takuan@localhost ~]$ vi tmp.txt
省略
~
~
"tmp.txt" 0L, 0C                                                        0,0-1        全て

[1]+  Stopped                 vim tmp.txt

→viでtmp.txtを開き、ctr+z で中断


[takuan@localhost ~]$ find / -name *.txt
find: /var/cache/mod_proxy: 許可がありません
省略

^Z
[2]+  Stopped                 find / -name *.txt

→findコマンドで検索中にctr+zで中断


[takuan@localhost ~]$ jobs
[1]-  Stopped                 vim tmp.txt
[2]+  Stopped                 find / -name *.txt


→現在のジョブの表示



[takuan@localhost ~]$ bg %2
[2]+ find / -name *.txt &

→bgコマンドにてバックグランドでfindコマンドを実行

[takuan@localhost ~]$ jobs
[1]+  Stopped                 vim tmp.txt
[2]-  Running                 find / -name *.txt &


jobsコマンドにて確認すると[2]のfindコマンドがRunningとなっている。




省略・・・
find: /etc/cups/ssl: 許可がありません

[2]-  Exit 1                  find / -name *.txt


→[2]がバックグランドで実行が終わる。


[takuan@localhost ~]$ jobs
[1]+  Stopped                 vim tmp.txt





 
サーバ運用(ランキング)


blogram投票ボタン




サーバ構築(ランキング)を見る。



トラックバック(0)

このブログ記事を参照しているブログ一覧: bg  ジョブ バックグラウンド 実行 切り替え

このブログ記事に対するトラックバックURL: http://websky21.com/MT/mt-tb.cgi/827