Sorted list by time of spu processing


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sorted list by time of spu processing
# 1  
Old 03-03-2010
Sorted list by time of spu processing

Hi,
i have to make a command in unix system which make a sorted list by cpu time (not %cpu ). If the application exists more than a time I would like to keep only one copy.

Could you help me please ???

P.s : I am trying -->
Code:
ps aux --sort -%cpu | uniq

but I understand that is wrong

Last edited by radoulov; 03-04-2010 at 04:51 AM.. Reason: Use code tags please!
# 2  
Old 03-04-2010
Code:
ps aux --sort %cpu |
  perl -nle'/\s+\d?:\d+\s+(.+?)$/;print unless $_{$1}++
  '

But please give an example; do you need all the entries if the same application is invoked with different arguments?

Last edited by radoulov; 03-04-2010 at 04:59 AM..
# 3  
Old 03-04-2010
For example
Code:
USER   PID   %CPU %MEM   VSZ   RSS TTY   STAT START TIME COMMAND
root  28755  0.0  0.0  49588  3052 ?     Ss   11:32   0:00     login -- petros
root  30041  0.0  0.0 49588 3176 ?        Ss   11:44   0:00 login -- petros
root  30042  0.0  0.0 49588 3176 ?        Ss   11:44   0:20 login -- pet

I want to print
Code:
USER    PID      TIME  COMMAND
root    28755    0:00  login--petros
root    30042    0:20 login --pet

If thera are two entries to keep the entry with smalest pid.
And the list is sorted by Time.

PS:This time Time refers to cpu time for command execution ??

Last edited by radoulov; 03-04-2010 at 06:29 AM.. Reason: Added code tags ...
# 4  
Old 03-04-2010
You could try something like this:

Code:
ps aux | perl -nle'
    print and next if $. == 1;
    if (/^\w+\s+(\d+)\s+.*?[\d:]+\s+(\d+):(\d+)\s+(.*)?$/) {
        $_{$4} = [ $1, $2, $3, $_ ];
        $_{4}->[0] > $1 and $_{$4}->[0] = $1;
    }
    print join $/, map $_{$_}->[3],
      sort { $_{$a}->[1] <=> $_{$b}->[1] || $_{$a}->[2] <=> $_{$b}->[2] }
      keys %_
      if eof'


Last edited by radoulov; 03-04-2010 at 11:03 AM.. Reason: Corrected.
# 5  
Old 03-04-2010
thanks a lot !
it is exactly what i want.
# 6  
Old 03-04-2010
Hm, sorry,
the code was wrong, use this one instead:

Code:
ps aux | perl -nle'
    print and next if $. == 1;
    if (/^\w+\s+(\d+)\s+.*?[\d:]+\s+(\d+):(\d+)\s+(.*)?$/) {
      next if exists $_{$4}->[0] and $_{$4}->[0] < $1;
      $_{$4} = [ $1, $2, $3, $_ ];
      }    
    print join $/, map $_{$_}->[3],
      sort { $_{$a}->[1] <=> $_{$b}->[1] || $_{$a}->[2] <=> $_{$b}->[2] }
      keys %_
      if eof'

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

List all files and directories in the current directory separated by commas and sorted by crtime

What I know so far: ls -A will list all files except those starting with a dot ls -d will list all directories ls -m will separate contents by commas For getting crtimes use: stat filename will give me the inode number or ls -i filename will give... (13 Replies)
Discussion started by: chstewar
13 Replies

2. Shell Programming and Scripting

Generate sorted awk array for further processing

Hello to all, I have and input file like this: Objects (id: bounding-box centroid area mean-color): 0: 800x800+0+0 406.6,390.9 378792 srgb(0,0,0) 11: 240x151+140+624 259.5,699.0 36240 srgb(255,255,255) 6: 240x151+462+176 581.5,251.0 36240 srgb(255,255,255) 7: 240x151+87+257... (2 Replies)
Discussion started by: Ophiuchus
2 Replies

3. Shell Programming and Scripting

Inserting lines from one file to a sorted list

Hello friends! I am working a Psychology/Neuro* project where I am sorting inline citations by category. The final step of the process has me a little stuck. I need to take citations from a text list and sort them in another text file. Here is a file X example... (1 Reply)
Discussion started by: danbroz
1 Replies

4. Homework & Coursework Questions

Display sorted list using sed command

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write a command line that will display a sorted list of logged in users. Just display the username and no other... (5 Replies)
Discussion started by: kofine05
5 Replies

5. Shell Programming and Scripting

Match and insert in a sorted list

I have a sorted list (python) and I want to insert a string if it matches the pattern in list. Example : Sorted List Above list is in sorted order. I need to insert a name in sorted order and also if the name already exist then it should be inserted before the existing... (1 Reply)
Discussion started by: pratapsingh
1 Replies

6. Shell Programming and Scripting

How to get a very big file sorted by contents of another variable list in one pass?

I have two list.... One has 17m (yes that's million) records in it which relate to the path and file name of individual text files. At the start of the pathname is a two character identifier identifying which category it belongs in as identified by a second file with the two character lookup... (10 Replies)
Discussion started by: Bashingaway
10 Replies

7. UNIX for Dummies Questions & Answers

grep content of files sorted by time stamp

egrep Date: *.html > out.htm I would like to grep the match as sorted by time stamp of the html files. how do I do that? (1 Reply)
Discussion started by: zer0
1 Replies

8. Shell Programming and Scripting

Remove lines, Sorted with Time based columns using AWK & SORT

Hi having a file as follows MediaErr.log 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:12:16 84 Server1 Policy1 Schedule1 master1 05/08/2008 02:22:47 84 Server1 Policy1 Schedule1 master1 05/08/2008 03:41:26 84 Server1 Policy1 ... (1 Reply)
Discussion started by: karthikn7974
1 Replies

9. Shell Programming and Scripting

Trying to get list of logged on users sorted

I'm trying to execute a single shell command that will give me a sorted list of all the users currently logged into the system, displaying the users name as it appears in /etc/passwd. I've tried awk -F: '{print $1}' /etc/passwd | xargs finger -s | cut -c11-28 | uniq This list whoever does... (7 Replies)
Discussion started by: kungfuice
7 Replies
Login or Register to Ask a Question