Results 1 to 6 of 6
i'm using RHEL.i'm new to linux and shell scripting.
i got this command that shows cpu usage :
"ps ux | awk '/process_name/ && !awk/ { print $2}"
1)can someone ...
- 07-23-2007 #1Just Joined!
- Join Date
- Jul 2007
- Posts
- 12
how to include command line in c program?
i'm using RHEL.i'm new to linux and shell scripting.
i got this command that shows cpu usage :
"ps ux | awk '/process_name/ && !awk/ { print $2}"
1)can someone explain me what each thing signifies?
i know ps-process stat
awk-Find and Replace text
2)also..i;ve to write a c code.
how do i include this line in c so that it is executable in linux?
3)for example: i have to read a file from /proc/stat
how can i do that in c program?
in shell it is 'cat'...
like to print the file stat from /proc
whats the code for that?
thanks in advance
- 07-24-2007 #2
i'm not sure about 1 and 3,
to write a command line program..it's very easy ...
hi.c
-----
main(int argc,char [] argv){
//some initial variables
if(argv[1] == 'a'){
//call some function
}
else if(argv[2] == 'b'){
//call some function-2
}
}
---------
gcc hi.c
./a.out a b
that' s it
}- Lakshmipathi.G
-------------------
FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
-------------------
- 07-24-2007 #3Just Joined!
- Join Date
- Nov 2006
- Location
- Hyderabad
- Posts
- 85
- 07-24-2007 #4
Reading a file in C is a very simple task: if you don't know how, I'd recommend studying up some more on C before trying to write anything.
If you want to just print a file to stdout:
getc(FILE *) returns the next character (or the special symbol EOF if at the end of file). putchar(char) prints a character to stdout.Code:int c; FILE *file; file = fopen("file", "r"); while((c = getc(file)) != EOF) putchar(c); fclose(file);DISTRO=Arch
Registered Linux User #388732
- 07-25-2007 #5Just Joined!
- Join Date
- Nov 2006
- Location
- Hyderabad
- Posts
- 85
- 07-25-2007 #6
I actually was referring to kits, not you. Though with cat, since it takes in a filename, you don't need to do "cat < /proc/stat". You can just say "cat /proc/stat".
My message to kits is just that if you're going to try writing a full program in C, it would likely be useful to know how to do I/O first...DISTRO=Arch
Registered Linux User #388732


Reply With Quote
