#!/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/