Skip to content
Advertisement

How I can count how many suspended proceses there are in a shell script linux bash

I tried to write a shell script that shows and counts how many suspended processes there are.

But I succeeded only to show the suspended processes with:

JavaScript

I tried to count the suspended processes with:

JavaScript

Of course this didn’t work because it counted every word there was even with the first row that had the USER PID STAT COMMAND.

Can you give me any suggestion on how I should do it? Also here is the output for "ps aux | awk '$8~/T/" after I stopped some sleep processes.

JavaScript

Advertisement

Answer

additional characters can be added to the state field (depending on the options you use), so this might be a safer approach:

JavaScript

to count how many processes you have with a header :

JavaScript

to skip the header :

JavaScript

one line version :

JavaScript

within single awk :

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement