LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 05-03-2016, 10:55 AM   #1
aamir100
LQ Newbie
 
Registered: May 2016
Posts: 7

Rep: Reputation: Disabled
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
 
Old 05-03-2016, 11:31 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,695

Rep: Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972Reputation: 7972
Quote:
Originally Posted by aamir100 View Post
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.
 
Old 05-04-2016, 12:56 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,949

Rep: Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326Reputation: 7326
duplicate, reported
 
  


Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use web to invoke php program, and the php program call c program bellhuang Linux - Server 10 01-13-2014 06:09 AM
LXer: Can't Program, won't Program? Then Mash the Web with Mozilla's Ubiquity LXer Syndicated Linux News 0 05-01-2010 12:30 PM
open source dvd/cd copy program? burning on the fly program? vieya Linux - Software 3 12-14-2009 09:16 PM
Total recovery: Which program? ghost4linux, YaST2? Best drive imaging program? lagu2653 Linux - Software 1 06-20-2005 01:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:09 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration