[Bash] job control
Bash is built to handle multiple programs running in parallel.
time cat
Type time cat
and then hit ctrl-c before one second, as close as possible without going over:
$ time cat
^C
real 0m0.920s
user 0m0.004s
sys 0m0.000s
ctrl-c
Terminate a process in the foreground.
ctrl-z
Put a process in the background.
fg JOB
Move a process from the background to the foreground by its JOB.
~ $ cat
^Z
[1]+ Stopped cat
~ $ echo wow
wow
~ $ fg %1
cat
cool
cool
You can type jobs
to see what jobs are running.
If you just type fg
, it brings back the last job, or you do fg %1
which brings back the first job.
kill
You can kill the program
# kill the second job
kill -9 %2
job syntax
When you background a process with ctrl-z, the shell prints a message with [N]. N is the job id. Use %N to refer to a particular job or:
%%
- the most recent job
&
- Another way to background a process
$ ~ node &
[1] 29877
The job id of node is 1 and the process id is 29877. Job ids are local to a shell session, but process ids are global across the entire system.
~ $ perl &
[1] 29870
~ $ pgrep perl
29870
~ $ kill %1
[1]+ Terminated perl
pgrep
Seach for a process by its name
pkill
Kill the program by its name
# run a watch cmd
$ watch -n1 date
# grep the watch cmd
$ pgrep watch -lf
# kill the watch cmd
$ pkill watch
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2023-06-26 [Web] HTTP1,2,3
2023-06-26 [Javascript] this: What get logged?
2023-06-26 [Javascript] Async await in Call stack
2020-06-26 [ML L3] SVM Intro
2019-06-26 [Functional Programming] Partten: When Object props satisfies function condition then do something
2019-06-26 [Algorithm] Martrix Spirals
2016-06-26 [Javascript] Ex: concatAll, map and filter