how to compile this simple program???

From: David (dz1976_at_hotmail.com)
Date: 08/27/03


Date: 27 Aug 2003 13:00:35 -0700

i am trying to compile the following with gcc on a RH 9.0 box:

#include <sys/types.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdio.h>

/* resource.c */

int main(int argc,char* argv[]){
    struct rusage r_usage;
    struct rlimit r_limit;
    getrusage(RUSAGE_SELF, &r_usage);
    printf("User: %ld.%06ld\n",r_usage.ru_utime.tv_sec,
                               r_usage.ru_utime.tv_usec);
    getrlimit(RLIMIT_FSIZE,&r_limit);
    printf("Current FSIZE limit: soft = %ld, hard = %ld\n",
           r_limit.rlim_cur,r_limit.rlim_max);
    return 0;
}

with:

gcc -o resource resource.c

but it came back with the error that says 'struct rusage r_usage' is
undeclared (it also complain about 'struct rlimit'). i am sure that i
have missed something so gcc is not able to find the definition of the
rusage strrct but since this is the first time i am trying to program
in linux, i don't know how to solve that. i have googled around for a
while with no avil. can someone tell me what's wrong? thanks!



Relevant Pages

  • Re: how to compile this simple program???
    ... > i am trying to compile the following with gcc on a RH 9.0 box: ... > gcc -o resource resource.c ... > but it came back with the error that says 'struct rusage r_usage' is ... Are you sure you don't have a cut-and-paste error in your ...
    (comp.os.linux.development.apps)
  • Re: data types
    ... Usually short is smaller than an int. ... Your compiler is either *really* old or broken or both. ... recommend either a version of gcc,, or Visual Studio ... Microsoft's Visual Studio Express has an onerous EULA). ...
    (comp.lang.c)
  • Re: stream io in c
    ... zero to 255, putchar'ing in the body of the loop, then redirecting output ... int main ... // gcc -o chars mkchars1.c ... This compiles but gcc warns of incompatible pointer types. ...
    (comp.lang.c)
  • Re: gcc bug? Openoffice port impossibel to compile on 4.8
    ... remove this silly "bitten by the Linux bug" and the red-herring of gcc ... struct bar {int a; int b;} dapper; ... The *warning* emitted by gcc when enough analysis is done (e.g. ...
    (freebsd-hackers)
  • Re: [PATCH 3/7] PCI PM: Fix saving of device state in pci_legacy_suspend
    ... so the icache is going to scream but gcc folks know ... I'll see Michael what exactly the situation is here and if we ... int smp_request_message_ipi ...
    (Linux-Kernel)