#!/usr/bin/perl -w use strict; use warnings FATAL => 'all'; foreach (`ps axo state,user,pid,%cpu,%mem,vsz,rss,tt,state,start,time,command`) { chomp; if (/^STAT\s*(.+)/) { printf "%s\n", $1; } elsif (/^(\S+)\s*(.+)/) { my $state = $1; my $line = $2; if ($state =~ /W/) { printf "%s\n", $line; } } }