Unix system calls with c
I am a beginner and have RH 8 installed. We have UNIX Lab and i have to do c programs with the help of unix system calls.... caan u plz help me,,,
Is gcc enough to compile a c program ... plz help?? |
Yes, it is. When you have your code written, let's say in myprog.c you can compile it using
gcc -o progname myprog.c The executable created will be 'progname'. Do you have more specific questions? I'm not sure if I understand what you mean. |
I mean i had to generate some commands like cat,grep with the help of unix system calls.
I have to include the header files fcntl.h,unistd.h.. Is all these header files availabe in Linux.. and where i have to type the code? Can i compile it in any dir? |
What do you mean by generate??
I think you probably mean executing them from C. Am I right? or are you trying to write programs that duplicate their functions? I suspect you'll not be posting this if that's the case. Quote:
|
I probably misunderstood your question.
Yes, all these headers are available. |
Sounds that you wanna execute those commands from within a C prog. So you may use commands like "system" and the "exec" family. do man system and man exec for more info. However for simplicity to run ls for example do write system("ls");
|
Hi pengui,
Possibly all the people above may have solved your problem, still I am posting this because even I was at this stage someday. See gcc is a compiler in Linux, which helps compile C files, no matter where these files exists (in any directory), only thing is that you should be able to run gcc from that. [type gcc and if the output on screen is "no files specified", it is perfect]. HEader files are kept in /usr/include/ directory, and there are a large no of them including the above ones. As for your program , here is a sample snippet: //test.c #include<stdio.h> #include<stdlib.h> int main() { system(" ls -l"); return 0; } you can replace whatever command in " " in system call. like cat, grep etc. [but please take care not to use ' " ' anywhere or they will create problem. use \" if you need to have ' " ' within your command. File name of above prog is file.c so: type gcc file.c -o file; which will create a output file 'file' in the same directory as you compiled in. execute it by ' ./file '. ./ is required to tell bash to execute from the local directory. if it does not work and some problem of header files exists: use gcc file.c -o file -I/usr/include/ where you can replace /usr/include/ with the path where gcc can find its header files [if you know where they are. Hope it helps. |
:)
|
Quote:
|
Materials for learning C programing for unix system calls
Hey,
I'm second year B tech student, in our curriculum we have UNIX programming alb where we have to write system calls using C/ C++ programming. I was wondering if you could help me in recommending some materials for writing system calls using C program ? Please help Urgent ! I can write C programs, I just need the specific thing for writing system calls ( basically writing programs for UNIX environment ) |
You shouldn't write system calls, only use them. Examples: open/close/read/write (later: lseek/ioctl/fcntl etc). See the manual.
|
Thanks
Thanks for your help
Quote:
|
Quote:
But they are asking us to write the primitive function in C (of the read write system calls). Is it really tough to wirte these primitive functions ? |
|
All times are GMT -5. The time now is 01:26 AM. |