LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   help me with this program (https://www.linuxquestions.org/questions/programming-9/help-me-with-this-program-4175578907/)

aamir100 05-03-2016 10:55 AM

help me with this program
 
I have written this program to print the voluntary and involuntary context switches. I am getting few errors. please help me to remove these errors

#include<stdio.h>
#include<time.h>
#include<stdint.h>
#include<sys/time.h>
#include<sys/resource.h>
int main(int argc, char* argv[])
{

struct rusage{

long ru_maxrss;

long ru_ixrss;

long ru_idrss;

long ru_isrss;

long ru_minflt;

long ru_majflt;

long ru_nswap;

long ru_inblock;

long ru_oublock;

long ru_insgsnd;

long ru_msgrcv;

long ru_nsignals;

long ru_nvcsw;

long ru_nivcsw;

};
rusage ru;

getrusage(RUSAGE_SELF, &ru);
printf("voluntary context switches%ld, involuntary context switches %ld",ru.ru_nvcsw,ru.ru_nivcsw);
return 0;
}

I am using Turbo C++, I m getting few errors. I m getting errors on using three header files #include<stdint.h>
#include<sys/time.h>
#include<sys/resource.h> , and function getrusage() should have a prototype. and undefined symbol RUSAGE_SELF please help me to remove these errors

TB0ne 05-03-2016 11:31 AM

Quote:

Originally Posted by aamir100 (Post 5540014)
I have written this program to print the voluntary and involuntary context switches. I am getting few errors. please help me to remove these errors
Code:

#include<stdio.h>
#include<time.h>
#include<stdint.h>
#include<sys/time.h>
#include<sys/resource.h>
int main(int argc, char* argv[])
{
 
struct rusage{

long ru_maxrss;
long ru_ixrss;
long ru_idrss;
long ru_isrss;
long ru_minflt;
long ru_majflt;
long ru_nswap;
long ru_inblock;
long ru_oublock;
long ru_insgsnd;
long ru_msgrcv;
long ru_nsignals;
long ru_nvcsw;
long ru_nivcsw;

};
rusage ru;

getrusage(RUSAGE_SELF, &ru);
printf("voluntary context switches%ld, involuntary context switches %ld",ru.ru_nvcsw,ru.ru_nivcsw);
return 0;
}

I am using Turbo C++, I m getting few errors. I m getting errors on using three header files
#include<stdint.h>
#include<sys/time.h>
#include<sys/resource.h> , and function getrusage() should have a prototype. and undefined symbol RUSAGE_SELF please help me to remove these errors

First, use CODE tags when posting source code. Secondly, what errors are you getting on the header files?

For the prototype message, you've not declared it (as in, putting "void getrusage.....") before entering main. And the undefined symbol is VERY obvious...you're using it, but haven't DEFINED IT ANYWHERE. Also...Turbo C++ is for Windows....the rusage things you're doing here appear to be pulled almost verbatim from the getrusage man page in Linux.

pan64 05-04-2016 12:56 AM

duplicate, reported


All times are GMT -5. The time now is 05:54 PM.