simple script

Hi,

I just need a shell script to find out the processes taking longer time...(Unix/Linux)

Urgent response needed..

Rajiv

try this:

 ps | awk '{print $7}' | sed '1d'| sort -r

you can change $7 to whichever column your "TIME" field appears after the ps command. Once this is sorted from higher to lower you can select which process takes the longest.

Hi,

I dont know much about shell scripting..I think the above should work..But can u say me what after printing value in the variable what does sed '1d' does...I am very thankful to you for tour help..as within an hour I got a respone..That is so nice of you..

Thank You once again...
Rajiv

you are welcome..

sed '1d' deletes the first line of the output:

when i did ps on my system i got :

PID PPID PGID WINPID TTY UID STIME COMMAND
3404 1 3404 3404 con 1006 18:38:19 /usr/bin/bash
2136 3404 2136 3256 con 1006 18:50:10 /usr/bin/tcsh
1920 2136 1920 1160 con 1006 18:50:23 /usr/bin/bash
3312 1920 3312 1488 con 1006 19:48:40 /usr/bin/ps

i am using cygwin not a unix system.

the awk part extracts the 7th column in this case the STIME..

i want to delete the STIME row which is the first row that i deleted using the sed statement..

what is your output of the ps command?

ps
PID TTY TIME CMD
1541 pts/13 00:00:00 bash
1567 pts/13 00:00:00 ps

I changed it to 3.. for the time
But this wont show background processes right

Will this one work

top -ocpu

Reg urs 7th column in starting time and not the time taken by the process...