Thursday, January 12, 2023

[Linux] 使用 bash shell 監測某個 daemon 的執行緒數量

 #!/bin/sh

# Define the process name

process_name=rsyslogd


# Get minimum number of threads from command line parameters

process_min_threads=$1


# Calculate number of threads for the given process name

num_threads=`ps -e -T -f | grep “${process_name}“ | grep -v “grep” | wc -l`


# Restart process when thread count is less than expected

if [ ${num_threads} -lt ${process_min_threads} ]; then


    echo “Need to restart ${process_name} since current thread num ${num_threads} is less than ${process_min_threads}“


fi


From:

https://ephrain.net/linux-%E4%BD%BF%E7%94%A8-bash-shell-%E7%9B%A3%E6%B8%AC%E6%9F%90%E5%80%8B-daemon-%E7%9A%84%E5%9F%B7%E8%A1%8C%E7%B7%92%E6%95%B8%E9%87%8F/

No comments:

Post a Comment

n8n index

 【n8n免費本地端部署】Windows版|程式安裝x指令大補帖  【一鍵安裝 n8n】圖文教學,獲得無限額度自動化工具&限時免費升級企業版功能