[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Linuxthreads and getrusage
From: |
Dominik Strasser |
Subject: |
Linuxthreads and getrusage |
Date: |
Wed, 24 Jan 2001 16:27:22 +0100 |
Hello,
I am encountering some problems when using getrusage on Linux in a
multithreaded program:
When specifying RUSAGE_SELF I get the correct info regarding the used
CPU time, but the time returned is only the time for the main thread.
When specifying RUSAGE_CHILDREN I get a 0.
I tried the same program using fork and there I get correct results both
for RUSAGE_SELF and RUSAGE_CHILDREN.
SUN Solaris returns the time used in all threads when specifying
RUSAGE_SELF.
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <pthread.h>
void* function(void *)
{
for (int i =0; i< 100000; ++i)
{
printf("Juhuthread\n");
}
return 0;
}
int main()
{
struct rusage r;
for (int i =0; i< 20000; ++i)
{
printf("Juhu\n");
}
#ifdef FORK
if(fork() == 0)
{
function(0);
return 0;
}
else
{
wait(0);
}
#else
pthread_t thread;
void *aa;
pthread_create(&thread, 0, function, 0);
pthread_join(thread, &aa);
#endif
getrusage(RUSAGE_SELF, &r);
fprintf(stderr, "self time = %ld\n", r.ru_utime.tv_sec * 1000L +
r.ru_utime.tv_usec/1000L);
getrusage(RUSAGE_CHILDREN, &r);
fprintf(stderr, "child time = %ld\n", r.ru_utime.tv_sec * 1000L +
r.ru_utime.tv_usec/1000L);
return 0;
}
compile either with -DFORK or not. Redirect stdout to /dev/null. The
program is really stupid but I just needed some code which consumed some
time.
Does anybody have any clues ?
Dominik
--
Dominik Strasser | Phone: +49 89 636-43691
SIEMENS AG | Fax: +49 89 636-42284
CT SE 4 | E-Mail:address@hidden
Otto-Hahn-Ring 6 |
D-81739 Muenchen | Room: 53-263
- Linuxthreads and getrusage,
Dominik Strasser <=