[Bash] Kill command
The kill command sends a signal to a process, usually to terminate the process.
kill PID
This command sends the SIGTERM
signal to the process with the given PID.
Common Options:
-l
: List all signal names.
-9
or -KILL
: Send the SIGKILL
signal to forcefully terminate a process.
-15
or -TERM
: Send the SIGTERM
signal to gracefully terminate a process (default).
# Terminate a process with PID 1234:
kill 1234
# Forcefully terminate a process with PID 1234
kill -9 1234
# List all signal names
kill -l
Pratice
# Find the process IDs and names of the zsh process
$ pgrep -l zsh
1092 zsh
# Find the process IDs of processes for the current user:
pgrep -u $USER
#!/bin/zsh
echo "Enter the process name to terminate: "
read process_name
pids=$(pgrep "$process_name")
# if pids length is 0
if [ -z "$pids" ]; then
echo "No process found with the name $process_name."
exit 1
fi
echo "Found the following PIDs for $process_name: $pids"
echo "Terminating processes..."
for pid in $pid; do
kill -9 $pid
echo "Terminated process with PID $pid"
done
pgrep
"$process_name": Finds all PIDs for the given process name.if [ -z "$pids" ]; then ... fi
: Checks if any PIDs were found.for pid in $pids; do ... done
: Iterates over each PID and sends the SIGKILL signal to terminate it.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2023-05-24 [HTML 5] Detect visualViewport change
2023-05-24 [React Typescript] useRef with HTML Elements
2023-05-24 [Rust] Option vs Result
2023-05-24 [Rust] Handle Error
2023-05-24 [Rust] Option
2022-05-24 [Next.js] Override the Default Next.js Document
2022-05-24 [Next.js] Override the Default App Component in Next.js