假如我想批量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."
terminate_ascp.sh
.chmod +x terminate_ascp.sh
../terminate_ascp.sh
. You might need to use sudo
if the processes are not owned by your user.