How many cores is a process using in Linux

Script to check no. of cores being utilized by a process in linux. Save the script below as a shell script and execute:
[root@~]#  sh check_cpu_cores.sh  1111

#!/bin/bash
pids=()
while [ $# != 0 ]; do
pids=("${pids[@]}" "$1")
shift
done
if [ -z "${pids[0]}" ]; then
echo "Usage: $0 <pid1> [pid2] ..."
exit 1
fi
for pid in "${pids[@]}"; do
if [ ! -e /proc/$pid ]; then
echo "Error: pid $pid doesn't exist"
exit 1
fi
done
while [ true ]; do
echo -e "\033[H\033[J"
for pid in "${pids[@]}"; do
ps -p $pid -L -o pid,tid,psr,pcpu,comm=
done
sleep 1
done

 

Category: BashLinuxShell Script

Tags:

Leave a Reply

Article by: Shadab Mohammad