getrusage(2) not returning number of context switches! (fwd)

Sachin Garg (sachin@cdacb.ernet.in)
Tue, 24 Nov 1998 20:36:13 +0530 (IST)


Hi all,

I am using the getrusage(2) system call to try and get various
parameters from a running process:

struct rusage
{
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};

The parameters I am interested in are :

1) User Time
2) System Time
3) Voluntary Context Switches
4) Involuntary Context Switches

I get the first two parameters fine but the Context switch field
always remains zero!

The code I run is:

#include <unistd.h>
#include <sys/time.h> /* For select() */
#include <sys/resource.h> /* For getrusage() */
main()
{
long int i;
struct rusage usage;

for(i=0; i<=1000000; i++) {

getrusage(RUSAGE_SELF, &usage);

printf("User time:\t %12.8f us\n",
(double)usage.ru_utime.tv_sec * 1E6 +
(double)(usage.ru_utime.tv_usec));
printf("System time:\t %12.8f us\n",
(double)usage.ru_stime.tv_sec * 1E6 +
(double)(usage.ru_stime.tv_usec));
printf("Voluntary Context Switches:\t %ld\n", usage.ru_nvcsw);
printf("Involuntary Context Switches:\t %ld\n",
usage.ru_nivcsw);
}
}

The same code running on a machine with similar configuration as mine
(100 MHz Pentium) but running Solaris 2.6 gives values for the context
switches.

I have a machine running Linux 2.0.33. Any ideas?

Please cc the reply to me also as I am currently not on this list.

Thanks a lot
sachin

********************************************************************
Sachin Garg Phone: +91-80-5584271/143/982
MTS
C-DAC, Fax: +91-80-5584893
Ramanshree Plaza,
2/1, Brunton Road,
BANGALORE 560 025 http://sangam.cjb.net
INDIA E-mail: sachin@cdacb.ernet.in
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
finger -l sachin@cdacb.ernet.in for PGP public key
*********************************************************************

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/