system calls vs libraries


 
Thread Tools Search this Thread
Top Forums Programming system calls vs libraries
# 1  
Old 03-03-2006
system calls vs libraries

Hi a Smilie ll,
I would like to know the differrences between sytem calls and libraries.

Last edited by RTM; 03-03-2006 at 09:13 AM.. Reason: OP posted link to start new thread
# 2  
Old 03-04-2006
An example of a system call is open(). A process calls open() to open a file. The open function that gets linked to the program does reside in a library. But it very quickly hands the request of to the kernel. The kernel will open the file if it can. And either a file descriptor or an error message are returned to the user.

On the other hand, fopen() is the kind of function the folks call a library function. It will open a file, but it is not a system call. It must call open() to get the job done. A library function usually sits on top of coreesponding system calls. Or a library might be, say, math functions that can be implemented without a system call.

The distinction between system calls and functions gets a little blurred every now and then. getpid() is a system call that returns the process id of the caller. HP figured out a clever way to get the pid without invoking the kernel. HP now calls these "lightweight system calls". But they aren't exactly ssytem calls any more. Most versions of unix will claim that there are several system calls to exec another program: execl(), execle(), execlp(), execv(), execve(), and execvp(). But generally, only execve() actually exists and the other "system calls" invoke it.

This is why Posix lumps system call and functions together and simply calls them "interfaces".
# 3  
Old 03-04-2006
to add on,

system calls are executed in kernel address space and libraries work in user address space
most of the system calls when triggered do experience a context switch to kernel mode from user mode
library calls are designed to act as wrapper to the system calls thereby reducing the load to calls made to kernel
in the above example given by [PER] you have packaged set of library called as STDIO lib

and it depends upon implementation where system call in one of the implementation would be interpreted as a library in another implementation
# 4  
Old 03-06-2006
One of the major difference is in the buffer handling. For eg: if you use printf() , it may handle the strings ,passed to it, in its own way and flush the buffer on its own decision. Sometimes printf() does not flush the buffer and you get weird results. But if you use a sytem call , write() instead of printf(), the buffer will be flushed immediately .

John Arackal
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

System Calls using C w/BASH

Hello all, I'm attempting to write a basic application that appends an arbitrary list of txt files to one txt file. So, for example, if the application is run like so: appendFileToFile file1.txt file2.txt file3.txt the system command should, hopefully be, cat >> testfile.txt I'm... (4 Replies)
Discussion started by: whyte_rhyno
4 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. 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

5. Programming

System calls

why user is not able to switch from user to kernel mode by writing the function whose code is identical to system call. (1 Reply)
Discussion started by: joshighanshyam
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?

open, creat, read, write, lseek and close Are they all primitive? :confused: *Another Question: is there a different between a system call, and an i/o system call? (2 Replies)
Discussion started by: PlunderBunny
2 Replies

9. 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

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