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/

[Linux] 最大執行緒數限制及當前執行緒數查詢

 1、總結系統限制有:

/proc/sys/kernel/pid_max #查系統支援的最大執行緒數,一般會很大,相當於理論值

/proc/sys/kernel/thread-max

max_user_process(ulimit -u) #系統限制某使用者下最多可以執行多少程序或執行緒

/proc/sys/vm/max_map_count

硬體記憶體大小



2、Java虛擬機器本身限制:

-Xms #intial java heap size

-Xmx #maximum java heap size

-Xss #the stack size for each thread



3、查詢當前某程式的執行緒或程序數

pstree -p `ps -e | grep java | awk '{print $1}'` | wc -l

pstree -p 3660 | wc -l



4、查詢當前整個系統已用的執行緒或程序數

pstree -p | wc -l


1、 cat /proc/${pid}/status


2、pstree -p ${pid}


3、top -p ${pid} 再按H 或者直接輸入 top -bH -d 3 -p ${pid}


top -H

手冊中說:-H : Threads toggle

加上這個選項啟動top,top一行顯示一個執行緒。否則,它一行顯示一個程序。


4、ps xH

手冊中說:H Show threads as if they were processes

這樣可以檢視所有存在的執行緒。


5、ps -mp <PID>

手冊中說:m Show threads after processes

這樣可以檢視一個程序起的執行緒數。


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

[Linux] cpu 相關 command

 判斷依據:

1.具有相同core id的cpu是同一個core的超執行緒。

2.具有相同physical id的cpu是同一顆cpu封裝的執行緒或者cores。


#邏輯CPU個數

cat /proc/cpuinfo | grep "processor" | wc -l

 

echo "physical CPU number:"

#物理CPU個數:

cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l

 

echo "core number in a physical CPU:"

#每個物理CPU中Core的個數:

cat /proc/cpuinfo | grep "cpu cores" | uniq | awk -F: '{print $2}'

 

#查看每個physical cpu上core id的數量,即為每個物理CPU上的core的個數

cat /proc/cpuinfo | grep "core id"

 

#是否為超執行緒?

#如果有兩個邏輯CPU core具有相同的”core id”,那麼超執行緒是打開的。

# 當然也可知直接查詢 /proc/cpuinfo 中的 "ht"這個flag

cat /proc/cpuinfo | grep flags | grep ht

 

#每個物理CPU中邏輯CPU(可能是core, threads或both)的個數:

cat /proc/cpuinfo | grep "siblings"

Linux Index

Computer Science from the Bottom Up

CPU上下文切換的次數和時間 (context switch)

Linux-Command Online Explain

  查 Wi-Fi  dongle chip

解析 Linux 共享記憶體機制

Shell Script 截取部份字串

What does the dot at the end of the permissions in the output of "ls -lah" mean?

ubuntu/debian 大部分都不啟用 selinux ,所以都沒有;但 redhat/centos 預設有啟用 selinux,就會有

sed

vim

Makefile

cpu 相關 command

最大執行緒數限制及當前執行緒數查詢

  

n8n index

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