Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | 51CTO学院 | CSDN程序员研修院 | OSChina 博客 | 腾讯云社区 | 阿里云栖社区 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏多维度架构

13.7. jobs

13.7.1. &

usage: command &

			
$ grep -r 'neo' / > result &
[1] 10414
			
			

13.7.2. Ctrl + Z

			
vim

$ vim

[2]+  Stopped                 vim


mutt

$ mutt

[3]+  Stopped                 mutt
			
			

13.7.3. jobs

			
$ jobs
[1]   Running                 grep -r 'neo' / > result &
[2]-  Stopped                 vim
[3]+  Stopped                 mutt
			
			

13.7.4. fg / bg

usage: fg [job_spec]

			
$ fg 2
			
			

usage: bg [job_spec ...]

			
$ cp -r /usr/ /tmp/
Ctrl + Z
[1]+  Stopped                 cp -r /usr/ /tmp/

$ bg
[1]+ cp -r /usr/ /tmp/ &

$ fg
cp -r /usr/ /tmp/
			
			

13.7.5. nohup - run a command immune to hangups, with output to a non-tty

			
nohup command > myout.file 2>&1 &
nohup command >/dev/null 2>/dev/null &
nohup command &>/dev/null
			
			

You may using 'jobs' to display task.

and using 'fg %n' to close that.

13.7.6. wait 等待后台任务运行结束

			
neo@MacBook-Pro ~ % sleep 10 &
[1] 2967

neo@MacBook-Pro ~ % wait
[1]  + 2967 done       sleep 10			
			
			

wait 将一只停留,等待 sleep 10 运行完毕。