![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to get the percentage of completion? during a copy! | wrapster | UNIX for Advanced & Expert Users | 7 | 05-24-2008 01:55 AM |
| how do I calculate percentage ? | the_learner | High Level Programming | 6 | 04-18-2007 04:40 PM |
| LPAR processor/virtual processor settings | guttew | AIX | 1 | 02-01-2007 01:52 PM |
| how to make percentage of a running script? | jimmbp | Shell Programming and Scripting | 1 | 01-31-2006 02:41 PM |
| Computung Percentage | preetikate | UNIX for Dummies Questions & Answers | 2 | 02-09-2004 10:13 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
How can I get a processor's CPU Percentage?
you know that.. in HP-UX..
in sys/pstat.h struct pst_status { long pst_idx; /* Index for further pstat() requests */ long pst_uid; /* Real UID */ long pst_pid; /* Process ID */ .... float pst_pctcpu; /* %cpu for this process during p_time .... } when, need to get a processor's cpu used %, we use pst_status.pst_pctcpu.. but i want to know other way.. not use pst_status.pst_pctcpu. How can I get that?? and what is p_time ?? |
|
||||
|
because..
first of all..
thanks for your kindly reply.. I want to know about getting cpu percentage not use structure because in SCO-UNIX, there is no cpu percentage ..but only cpu time ( timestruc_t pr_utime; ) so.. I asked get that percantage without structure.. I can get get cpu percentage in HP-UX using pstat.h.. but.. How can I get cpu percentage in SCO-UNIX ?? /** SCO-UNIX , procfs.h **/ typedef struct pstatus { .... pid_t pr_pid; /* Process id */ pid_t pr_ppid; /* Parent process id */ pid_t pr_pgid; /* Process group id */ pid_t pr_sid; /* Session id */ timestruc_t pr_utime; /* Process user cpu time */ timestruc_t pr_stime; /* Process system cpu time */ timestruc_t pr_cutime; /* Sum of children's user times */ timestruc_t pr_cstime; /* Sum of children's system times */ sigset_t pr_sigtrace; /* Mask of traced signals */ fltset_t pr_flttrace; /* Mask of traced faults */ sysset_t pr_sysentry; /* Mask of system calls traced on } pstatus_t; |
|
||||
|
I believe this is similar to what you read in /proc/stat on Linux. In Linux, you can read the timer ticks spent on user, system and IO, IRQ etc using /proc/stat. But you need to calculate the CPU % by adding the total time spent against each category. Generally following is a common approach. If you look at source of procps (vmstat.c) you might be able to get an idea how it's done on Linux.
All CPU = User + System + Idle time User CPU % = User / All CPU * 100% System CPU % = System / All CPU * 100% But you have to check where you can place pr_cutime and pr_cstime. It looks like it's part of User time. |
| Sponsored Links | ||
|
|