批量终结ascp linux系统中,批量停止kill进程

发布时间:2024年01月22日

假如我想批量kill ascp进程?

#!/bin/bash

# Get PIDs of all running ascp processes
pids=$(ps -ef | grep '[a]scp' | awk '{print $2}')

# Loop through each PID and try to terminate the process gracefully
for pid in $pids; do
    echo "Attempting to gracefully terminate ascp process with PID: $pid"
    kill -15 $pid
done

sleep 5

# Check if processes are still running and forcefully terminate if necessary
for pid in $pids; do
    if kill -0 $pid 2>/dev/null; then
        echo "Forcefully terminating ascp process with PID: $pid"
        kill -9 $pid
    fi
done

echo "All ascp processes have been handled."

  1. Save the script as terminate_ascp.sh.
  2. Make it executable: chmod +x terminate_ascp.sh.
  3. Run the script: ./terminate_ascp.sh. You might need to use sudo if the processes are not owned by your user.
文章来源:https://blog.csdn.net/qq_52813185/article/details/135736937
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。