The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-16-2001
sangjinn sangjinn is offline
Registered User
  
 

Join Date: Sep 2001
Location: Seoul,SouthKorea
Posts: 4
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 ??
  #2 (permalink)  
Old 10-16-2001
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,100
Kernels always have some code built in to gather statistics. In the case of cpus, several times a second a clock routine fires off and increments one element of a structure. The structure will have counters for idle, user, system, and so on.

In the old days, you could get the structure if you knew its name. You would run nlist(3) on the kernel's symbol table to get the address of the structure. Then you opened /dev/kmem. did a seek to the address and read the structure. The c definations of the structures were usually in /usr/include. This still can be made to work on hp-ux, but the required information is no longer supplied in /usr/include. Skilled gurus can reverse-engineer it, but it's difficult. Vic Able has done this to get lsof to work on recent versions of HP-UX, a feat that very few could match.

New system calls like pstat are the way of the future. And pstat works well enough. Why do you want an alternative?
  #3 (permalink)  
Old 10-17-2001
sangjinn sangjinn is offline
Registered User
  
 

Join Date: Sep 2001
Location: Seoul,SouthKorea
Posts: 4
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;
  #4 (permalink)  
Old 10-09-2008
Kosala Kosala is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 2
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:18 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0