- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: %CPU Info in TOP
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2004 09:27 AM
08-19-2004 09:27 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2004 09:36 AM
08-19-2004 09:36 AM
Re: %CPU Info in TOP
Per process CPU usage can be extracted using ps command
UNIX95= ps -ef -o pid,pcpu,args | sort -nbk 2
The above command line will list the processes sorted based on their CPU usage.
If you are looking for global CPU usage, you could use sar , vmstat or top itself
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2004 09:41 AM
08-19-2004 09:41 AM
Re: %CPU Info in TOP
TOP sorts based on %CPU. And yes I can get it from a top -d 1 command and read the file until I get to the line I can and grab it then. I am looking for something easier?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2004 10:25 AM
08-19-2004 10:25 AM
Re: %CPU Info in TOP
UNIX95= ps -ef -o pid,pcpu,comm | sort -nbk 2 | tail -1 | read PID PCPU PROCESS
echo "Process $PROCESS with pid: $PID is the top CPU process using $PCPU% of CPU time"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 02:21 AM
08-20-2004 02:21 AM
Re: %CPU Info in TOP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 02:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 02:52 AM
08-20-2004 02:52 AM
Re: %CPU Info in TOP
top -d 1 -n 1
-n --> number of process per
or just as,
top -d 1 -n 1 -f /var/tmp/cpuhigh.pid
If you put in cron it will update the file upto the stage.
HTH.
Regards
Muthu.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 03:11 AM
08-20-2004 03:11 AM
Re: %CPU Info in TOP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 03:30 AM
08-20-2004 03:30 AM
Re: %CPU Info in TOP
And top is little bit lagging on performance comparision on your requirement as,
test # time top -q -h -d 1 -n 1
CPU TTY PID USERNAME PRI NI SIZE RES STATE TIME %WCPU %CPU COMMAND
0 ? 725 root 152 20 285M 37220K run 37:29 0.39 0.39 ns-httpd
real 0m1.12s
user 0m0.00s
sys 0m0.08s
test # time UNIX95= ps -ef -o pid,pcpu,comm | sort -nbk 2 | tail -1
725 0.37 ns-httpd
real 0m0.23s
user 0m0.01s
sys 0m0.02s
Regards
Muthu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 03:40 AM
08-20-2004 03:40 AM
Re: %CPU Info in TOP
# top -d 1 -s 1 -n 5 -f /tmp/top.$$;tail -n 5 /tmp/top.$$ | awk '{if ($(NF-1) > 40) print $(NF-1)," ", $NF}'; rm /tmp/top.$$
(^ this will look for the top 5 processes and then check to see if any of them are using more than 40 percent of a cpu.
Or to sort [the top 50] processes by cpu and then by cpu percentage, use:
# top -d 1 -s 1 -n 50 -f /tmp/top.$$;tail -n 50 /tmp/top.$$ | sort -rn +0 +11; rm /tmp/top.$$
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2004 04:56 AM
08-20-2004 04:56 AM
Re: %CPU Info in TOP
XXXXXXXXXXXXXX top XXXXXXXXXXXXXXXXX
#!/bin/sh
top -n 1 -h -f /tmp/top$$
awk ' BEGIN {FOUND=0;COUNT=1}
(FOUND <= 0) {
FOUND=index($0, "LOAD")
HEADING=sprintf ("%s \n", $0 )
next
}
{
printf ("%s", HEADING )
printf ("%s \n", $0 )
exit
}
' /tmp/top$$
rm /tmp/top$$
xxxxxxxxxxxxxxxxxx vmstat XXXXXXXXXXXXXX
#!/bin/sh
#gather memory stats
vmstat 2 4 |tail -3 |awk '
{
for (i =1; i <=3; ++i)
{
split($18,c_id," "); c_id[i]
c_idtot += c_id[i]
c_idavg = c_idtot / 3
}
}
END{printf("CPU IDLE=%2d \n", c_idavg)}'