Problem with getrusage

We are trying to measure the amount of resources needed to run our program, written in C. Looking here and there, I found getrusage (2). So, yesterday I tried to write a simple code:


#include <stdio.h>
#include <errno.h>
#include <sys/resource.h>

int main(){
int y[100][100];
struct rusage *resource;
int x;

x = getrusage(0, resource);
printf("x = %d\n", x);
printf("errno = %d\n", errno);
return(0);
}

The result was not great. getrusage returned -1. According to the man page, non zero return value means it fails. The value of errno is 14.

What went wrong? Anybody?

Is there a better way to measure the amount of resources (memory, CPU, time) needed for a program? [Right now, I am looking at dtrace. Would it help?]

Tentang Budi Rahardjo

Teknologi informasi, security, musik, buku Lihat semua yang ditulis oleh Budi Rahardjo

6 Tanggapan to “Problem with getrusage”

Tinggalkan Balasan

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Ubah )

Twitter picture

You are commenting using your Twitter account. Log Out / Ubah )

Facebook photo

You are commenting using your Facebook account. Log Out / Ubah )

Connecting to %s

Ikuti

Get every new post delivered to your Inbox.

Bergabunglah dengan 542 pengikut lainnya.