By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,503 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

how do i compile this simple program???

P: n/a
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!
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
David wrote:
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>

[ . . . ]

but it came back with the error that says 'struct rusage r_usage' is
undeclared (it also complain about 'struct rlimit').


David,

Since your problem isn't really C-language-related, you'll have better
luck asking this on a newsgroup that deals with Linux. See the welcome
message for this group:

http://www.angelfire.com/ms3/bchambl...me_to_clc.html

For what it's worth, I compiled your code without problems on my FreeBSD
machine and on some Linux machine (I don't know if it was Red Hat).

Regards,

Russell Hanneken
rh*******@pobox.com

Nov 13 '05 #2

P: n/a
David wrote:
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').
As you know, none of <sys/types.h>, <sys/resource.h>, <sys/time.h>, and
<unistd.h> are standard C, but are properties of your implementation & OS.
Not only does that make questions about the off-topic here, but may be
the key to your problem.

Apparently your installed version of gcc does not recognize the struct
definitions in <sys/resource.h>. This is what you expect when using -ansi
or -std=c89 or -std=c99 or their synonyms. Compiling your code with the
flags to specify the non-standard language -std=gnu89 or -std=gnu99 (I had
thought the default was -std=gnu89, but it seems otherwise for you), I find
those diagnostics disappear.

Even if that works (and check with a gcc newsgroup where it is topical),
you have an error in your code. In printf("User: %ld.%06ld\n",r_usage.ru_utime.tv_sec,
r_usage.ru_utime.tv_usec);

r_usage.ru_utime.tv_sec should be a time_t, not a long. Simply casting it
with (long) should suffice. This would not normally be the way to do
things in comp.lang.c, since there is no reason to suppose that a time_t's
value will in general be representable in a long; however, your
non-standard application will -- for your particular and off-topic
implementation -- have no problem.

--
Martin Ambuhl

Nov 13 '05 #3

P: n/a
Russell Hanneken <rh*******@pobox.com> wrote in message news:<DT*****************@newsread4.news.pas.earth link.net>...
David wrote:
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>

> [ . . . ]

but it came back with the error that says 'struct rusage r_usage' is
undeclared (it also complain about 'struct rlimit').


David,

Since your problem isn't really C-language-related, you'll have better
luck asking this on a newsgroup that deals with Linux. See the welcome
message for this group:

http://www.angelfire.com/ms3/bchambl...me_to_clc.html

For what it's worth, I compiled your code without problems on my FreeBSD
machine and on some Linux machine (I don't know if it was Red Hat).


sorry for the OT question and i thank everyone for the answer so far.
i will repost the questino to the right group.
Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.