Skip to content

Instantly share code, notes, and snippets.

@unacceptable
Last active July 20, 2017 15:16
Show Gist options
  • Save unacceptable/5e7f4b96d8cad798bdd40688a6daca4f to your computer and use it in GitHub Desktop.
Save unacceptable/5e7f4b96d8cad798bdd40688a6daca4f to your computer and use it in GitHub Desktop.

processcount.sh

Description

This is a simple oneliner that I wrote so that I could quicly get an overview of the counts of each process.

NOTE:

Too many TASK_UNINTERRUPTIBLE processes can cause significant Disk Utilization.

Example

21:05 Mac Shell: processcount.sh/>$ process=( R S D K T Z X ) &&
> state=(
>     "(running)"
>     "(sleeping)"
>     "(sleeping)"
>     "(sleeping)"
>     "(stopped)"
>     "(zombie)"
>     "(zombie)"
> ) &&
> process_name=(
>     TASK_RUNNING
>     TASK_INTERRUPTIBLE
>     TASK_UNINTERRUPTIBLE
>     TASK_KILLABLE
>     TASK_STOPPED/TRACED
>     EXIT_ZOMBIE EDIT_DEAD
> ) &&
> counter=0 &&
> for i in "${process[@]}"; do
>     [[ "$counter" == "0" ]] &&
>         w | head -n 1;
>     printf "%s\t%d\t%s\t%s\n" \
>         "$i" \
>         "$(ps -ev | \
>             awk '{print $2}' | \
>                 grep -w "$i" -c)" \
>         "${state[$counter]}" \
>         "${process_name[$counter]}";
>     ((counter++))
> done;
21:05  up 3 days, 12:15, 3 users, load averages: 1.12 1.27 1.31
R	1	(running)	TASK_RUNNING
S	170	(sleeping)	TASK_INTERRUPTIBLE
D	0	(sleeping)	TASK_UNINTERRUPTIBLE
K	0	(sleeping)	TASK_KILLABLE
T	0	(stopped)	TASK_STOPPED/TRACED
Z	0	(zombie)	EXIT_ZOMBIE
X	0	(zombie)	EDIT_DEAD
21:05 Mac Shell: processcount.sh/>$
process=( R S D K T Z X ) &&
state=(
"(running)"
"(sleeping)"
"(sleeping)"
"(sleeping)"
"(stopped)"
"(zombie)"
"(zombie)"
) &&
process_name=(
TASK_RUNNING
TASK_INTERRUPTIBLE
TASK_UNINTERRUPTIBLE
TASK_KILLABLE
TASK_STOPPED/TRACED
EXIT_ZOMBIE EDIT_DEAD
) &&
counter=0 &&
for i in "${process[@]}"; do
[[ "$counter" == "0" ]] &&
w | head -n 1;
printf "%s\t%d\t%s\t%s\n" \
"$i" \
"$(ps -ev | \
awk '{print $2}' | \
grep -w "$i" -c)" \
"${state[$counter]}" \
"${process_name[$counter]}";
((counter++))
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment