Difference between system calls and normal functions in C


 
Thread Tools Search this Thread
Top Forums Programming Difference between system calls and normal functions in C
# 1  
Old 11-07-2011
Difference between system calls and normal functions in C

hello all,
i'm a beginner in linux programming. I need to know what is the difference between system calls and normal functions like fopen, fread etc in C?Also how to set permissions by using open system call?

Last edited by aarathy; 11-07-2011 at 02:24 AM..
# 2  
Old 11-07-2011
If i am not wrong the system call u talking about should be shell programming? As for the set permissions are u toking about file permissions(Read write execute). Give more information if not it hard for people to knw what you trying to say =)
# 3  
Old 11-07-2011
A regular function runs mostly in user space, and usually has a consistent interface across platforms (eg. the printf function takes the same arguments on Windows, AIX, Linux, BSD, MacOS, ...)
A system call, however, is the direct interface to the kernel functions. These are usually called by the C library as part of a regular function, and involve (as far as I know) triggering an interrupt. They are, by definition, very closely tied to the kernel, and not really that portable.
# 4  
Old 11-07-2011
Quote:
Originally Posted by aarathy
hello all,
i'm a beginner in linux programming. I need to know what is the difference between system calls and normal functions like fopen, fread etc in C?Also how to set permissions by using open system call?
System calls are fundamental, there's no deeper to go. Trace it with a debugger and you can't trace inside open(), because the program doesn't run open -- just tells the kernel to do so. The kernel just stops the program until it's finished.

fopen/fread/fclose are all just library functions inside libc. If they were built with debugging info, you could trace them. In the end, they use open/read/close like anything else which does file I/O.

To give permissions to open, you do open("filename", O_RDWR, 0666); where 0666 are octal permissions just like UNIX file attributes. They only matter when creating the file.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 11-07-2011
chmod() also is used to change permissions.

Depending on the UNIX, the standard system calls (ones required by POSIX standards)
all present the same interface for us to call. All open() calls present the same semantics for us to use, for example, on any standards conforming system. As long as the UNIX follows POSIX standards your code is portable.

What happens inside the call is never standard. Some UNIX implementions have a list of "syscalls" with entry points (function pointers). If you understand how those entry points work, you can call them directly - which you should only do in very clearly defined cases, such as system programming just for that OS and just for that version of the OS. Other systems do not support the idea of syscalls.

Then there is the system API. This is stuff which is specific to a particular OS. So it can't be used on another kinds of UNIX. Linux has loads of these. All UNIXes have them.
Sometimes these specific calls will "piggyback" on standard calls by adding extra flags or options. ioctl() often does this. So if you know everything about ioctl on HPUX, when you get to Linux there are some new things to learn.

An example of an altogether different function is Solaris' ustat(). Solaris also has seemingly odd "devices" like doors, that some other systems have not had up until now, so ioctl has to support them on Solaris. Linux had a door implementation, which I think is now deprecated. BTW all devices on a UNIX box are presented as files. No matter how odd the device might be, so there has to be a way to play with them.
This User Gave Thanks to jim mcnamara For This Post:
# 6  
Old 11-07-2011
Quote:
Originally Posted by jim mcnamara
BTW all devices on a UNIX box are presented as files. No matter how odd the device might be, so there has to be a way to play with them.
One big important exception to this is network interfaces.
# 7  
Old 11-07-2011
I don't get your point, network interfaces (sockets) are directly associated with file descriptors, at least in all of the boxes I've seen. Ditto eth0:, bge0:, etc., (nics) or whatever you call yours.

eth0: requires ifconfig because you are configuring a driver that subsequently talks to loads of other drivers: vhscsi, fp, etc.

If you are crazy, or on Linux you can call ioctl() on eth0:. Why? because ioctl works on files. You do Linux: try this -

Controlling Hardware with ioctls | Linux Journal
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Difference between normal Execute permission and GUID

Hi, Any can explain the difference between the normal execute permission for the file and GUID of the file. Since the normal execute permission has right to execute file why there is need of providing GUID for the same file. Also share some examples for SUID and SGID programs. Regards... (3 Replies)
Discussion started by: ksgnathan
3 Replies

2. UNIX for Dummies Questions & Answers

system calls in C

Hello, how would i be able to call ps in C programming? thanks, ---------- Post updated at 01:39 AM ---------- Previous update was at 01:31 AM ---------- here's the complete system call, ps -o pid -p %d, getpit() (2 Replies)
Discussion started by: l flipboi l
2 Replies

3. UNIX for Dummies Questions & Answers

About system calls.

Hi all, I am new here . I want to know about system call in detail. As system calls are also function .How system identifies it.:) (2 Replies)
Discussion started by: vishwasrao
2 Replies

4. Solaris

difference between RPATH and normal linking while building

while building in solaris and going for dynamic linking whats the difference or advantage or disadvantage in using RPATH vs while linking package and dependency libraries i need a little explanation about this RPATH option specially and the difference with normal linking using -L (0 Replies)
Discussion started by: mobydick
0 Replies

5. BSD

system calls

what is the functions and relationship between fork,exec,wait system calls as i am a beginer just want the fundamentals. (1 Reply)
Discussion started by: sangramdas
1 Replies

6. UNIX Desktop Questions & Answers

Using system calls

Hi, I'm new to UNIX system calls. Can someone share your knowledge as to how exactly system calls should be executed? Can they be typed like commands such as mkdir on the terminal itself? Also, are there any websites which will show me an example of the output to expect when a system call like... (1 Reply)
Discussion started by: ilavenil
1 Replies

7. Solaris

System calls ?

where can i find the differences in System calls between solaris and aix? also is it possible to find a comprehensive list of them? (1 Reply)
Discussion started by: TECHRAMESH
1 Replies

8. UNIX for Dummies Questions & Answers

System calls for cp and mv

Which system calls are made for operations cp and mv (2 Replies)
Discussion started by: gaurava99
2 Replies

9. UNIX for Dummies Questions & Answers

Any difference between the CLI of Mac OS X and normal UNIX?

Any? (11 Replies)
Discussion started by: edward
11 Replies

10. UNIX for Dummies Questions & Answers

System Calls

What does the system call "dup" do? What is the difference between dup and dup2 I have a fair idea of what it does but I am confused when its coming down to the exact details... Please help me!:confused: (2 Replies)
Discussion started by: clickonline1
2 Replies
Login or Register to Ask a Question