Ps commands trouble


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Ps commands trouble
# 1  
Old 02-27-2013
Ps commands trouble

Hi,

i am writing a bash file and need to list the command name and user for the busiest process ie the one using the greatest percentage of CPU time)

im kind of stuck. i know you should get the highest CPU , sort column 3 then take off the head but i'm un sure how would i do that?

echo "Busiest command and user:$(ps au | awk '/CPU%/ {print $3})"

thats what i did so far and im sure its wrong.

Any help?
# 2  
Old 02-27-2013
well you're getting close...

few things:

1. you didn't sort it.
2. /CPU%/ would find a line containing CPU%. You want the column, which you already address as $3

Code:
ps au | sort -rnk3,3 | head -1 | awk '{print $3}'

but awk is very powerful. you can find the maximum with it and drop two commands in the pipeline

Code:
$ ps aux | awk '$3 > max {max=$3;user=$1;cmd=$11} END { printf("busiest command: [%s] by user %s\n",cmd,user) }'
busiest command: [openvpn] by user nobody

# 3  
Old 02-27-2013
That first bit of code just returns "0.0"?

The second works but it says the busiest is /Applications/Firefox.app/Contents/MacOS/plugin-container.app/Contents/MacOS/plugin-container] by user Ryoukii

I need it to show the busiest process that is displayed when ps au is used? plugin-container is not there
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Trouble looping commands

Hi, I have encountered a problem that I am unable to find a workaround for. I have 52 numbers and I need to submit an individual job for each pair combination, so too many to do by hand. I have created a submission file (submission_code.sh) which contains the following code: gcta64... (2 Replies)
Discussion started by: tim.morris
2 Replies

2. Shell Programming and Scripting

Trouble using awk and sed commands

Hi i have a control file which i need to read. It is ',' separated. the 3rd parameter will be ';' separated. I have 2 files: /home/orig.txt /home/join.txt I need a O/P file name based on firstparameter_1.txt and it should have the content of /home/orig.txt and appended content from... (2 Replies)
Discussion started by: Ravindra Swan
2 Replies

3. Shell Programming and Scripting

Trouble passing commands with expect

Hello All, I hope someone could help me with this. I'm creating a shell script to run a process. The trouble is, part of the process has to be ran as a different user. I can 'su' to the user ok, but I'm having trouble passing a 'cd' command as well as some variables I set earlier in the... (1 Reply)
Discussion started by: bbbngowc
1 Replies

4. Shell Programming and Scripting

Trouble executing piped shell commands in perl code

I am trying to execute a piped combination of shell commands inside a perl program. However, it is not working as desired. This is my program, i am trying to print only filenames from the output of ls -l $ cat list_test #!/usr/bin/perl -w use strict; my $count=0; my @list=`ls -l|awk... (4 Replies)
Discussion started by: sam05121988
4 Replies

5. AIX

HACMP: difference between 'cl' commands and 'cli' commands

Hi all, I'm new in this forum. I'm looking for the difference between the HACMP commands with the prefix "cl" and "cli". The first type are under /usr/es/sbin/cluster/sbin directory and the second are under /usr/es/sbin/cluster/cspoc directory. I know that the first are called HACMP for AIX... (0 Replies)
Discussion started by: peppix
0 Replies

6. Shell Programming and Scripting

Can BASH execute commands on a remote server when the commands are embedded in shell

I want to log into a remote server transfer over a new config and then backup the existing config, replace with the new config. I am not sure if I can do this with BASH scripting. I have set up password less login by adding my public key to authorized_keys file, it works. I am a little... (1 Reply)
Discussion started by: bash_in_my_head
1 Replies

7. Programming

code that reads commands from the standard i/p and executes the commands

Hello all, i've written a small piece of code that will read commands from standard input and executes the commands. Its working fine and is execting the commands well. Accepting arguments too. e.g #mkdir <name of the directory> The problem is that its not letting me change the directory i.e... (4 Replies)
Discussion started by: Phrozen Smoke
4 Replies

8. UNIX for Dummies Questions & Answers

X trouble

Hi there, I'm new to unix-environments. I'm richard, and i'm mostly a web-developer, under php. I've done work in unix env before, but never had my own. Today, I've got debian 3.1 r4 from the official site, and i've attempted to install it twice. I installed it initially as "Desktop... (0 Replies)
Discussion started by: izua
0 Replies

9. UNIX for Dummies Questions & Answers

The trouble about SU ...

Hi all, having read lots of posts about SU I don't quiet understand this : I'm doing regular backups of my database (u betta do) and therefore use su - username -c "sqlscript special data_base" in a unixscript which is even using cron. (yep!) Now I need some other script, still with this... (4 Replies)
Discussion started by: nulnul7
4 Replies

10. UNIX Desktop Questions & Answers

trouble

Hello, The system reboots in single user mode what command to use to bring the system up regularly?? I get INIT: cannot create /var/adm/utmpx Type control -d to proceede with a normal startup or give root passwd for system maintaince. either way i don't have a change and ... (1 Reply)
Discussion started by: awk
1 Replies
Login or Register to Ask a Question