作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在编写一个脚本,该脚本将告诉我们 8 组计算机上有多少线程可用。我知道我可以使用
cat /proc/cpuinfo | grep processor | wc -l
ssh user@host <<'ENDSSH'
#commands to run on remote host
FindAvaiableThreads()
ENDSSH
ssh user@host2 << 'ENDSSH'
#commands to run on remote host
FindAvaiableThreads()
ENDSSH
...
ssh user@hostN << 'ENDSSH'
#commands to run on remote host
FindAvaiableThreads()
ENDSSH
name = username
ssh $name@remote1 'bash -s' < threadquery.scr
ssh $name@remote2 'bash -s' < threadquery.scr
ssh $name@remote3 'bash -s' < threadquery.scr
ssh $name@remote4 'bash -s' < threadquery.scr
ssh $name@remote5 'bash -s' < threadquery.scr
ssh $name@remote6 'bash -s' < threadquery_hyper.scr
ssh $name@remote7 'bash -s' < threadquery_hyper.scr
ssh $name@remote8 'bash -s' < threadquery_hyper.scr
NUMCPUS=`grep ^proc /proc/cpuinfo | wc -l`;
FIRST=`cat /proc/stat | awk '/^cpu / {print $5}'`;
sleep 1;
SECOND=`cat /proc/stat | awk '/^cpu / {print $5}'`;
USED=`echo 2 k 100 $SECOND $FIRST - $NUMCPUS / - p | dc`;
AVA=$(echo "$NUMCPUS-$NUMCPUS*$USED/100" | bc -l);
HOSTVAL=$(hostname)
echo "Estimated avaliable processors on $HOSTVAL";
echo $AVA | awk -F\. '{if(($2/10^length($2)) >= .5) printf("%d\n",$1+1);else printf("%d\n",$1)}';
NUMCPUS=`grep ^proc /proc/cpuinfo | wc -l`;
FIRST=`cat /proc/stat | awk '/^cpu / {print $5}'`;
sleep 1;
SECOND=`cat /proc/stat | awk '/^cpu / {print $5}'`;
USED=`echo 2 k 100 $SECOND $FIRST - $NUMCPUS / - p | dc`;
AVA=$(echo "$NUMCPUS-$NUMCPUS*$USED/100" | bc -l);
HOSTVAL=$(hostname)
THREADCORRECT=$(echo "$AVA/2" | bc -l);
echo "Estimated avaliable processors on $HOSTVAL";
echo $THREADCORRECT | awk -F\. '{if(($2/10^length($2)) >= .5) printf("%d\n",$1+1);else printf("%d\n",$1)}';
最佳答案
据我了解,您正在寻找的信息可以从“TOP”中检索到
http://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html
信息取自“TOP”的“Tasks”部分
#!/bin/bash
getthreads=`top -n 1 | awk '/running/ {print $2, $4, $6}'`
totalthreads=`echo "$getthreads" | awk ' {print $1 } '`
runningthreads=`echo "$getthreads" | awk ' {print $2 } '`
availablethreads=`echo "$getthreads" | awk ' {print $3 } '`
echo "Total threads: $totalthreads"
echo "Threads is use: $runningthreads"
echo "Threads available: $availablethreads"
关于bash - 确定远程机器上的空闲线程数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17752897/
我是一名优秀的程序员,十分优秀!