Systems Programming :: System Calls
Saturday, April 3, 2010
Operating system divides the system memory(RAM) into two parts.
The user space is the reserved memory area for user mode applications. User space can be swapped out to disk when necessary. Normally the kernel space is not swapped out to disk.
The kernel provides important services for the user mode applications.
Relation between kernel space and the user space
Note: I have used open() system call for this demontration.
void main()
{
printf("This is a user mode application\n");
......................................
......................................
......................................
int FD=open("MyFile.txt",0);
......................................
......................................
}
User Space
_______________________________________________________
Kernel Space
int open(char *_fileName, int mode)
{
......................................
......................................
push dword mode
push dword flags
push dword _fileName
mov eax, 5
add esp, byte 12
......................................
......................................
......................................
}
Difference between Library Functions and System Calls
Generally performs an single specific operation
May call system calls
May perform more than one task
More reliable than system calls
The relationship between system calls and library functions can be depicted as follows.
- Kernel Space
- User Space
The user space is the reserved memory area for user mode applications. User space can be swapped out to disk when necessary. Normally the kernel space is not swapped out to disk.
The kernel provides important services for the user mode applications.
- Opening files
- Reading files
- Writing to files
- Making network connections
- Making new processes
Relation between kernel space and the user space
Note: I have used open() system call for this demontration.
void main()
{
printf("This is a user mode application\n");
......................................
......................................
......................................
int FD=open("MyFile.txt",0);
......................................
......................................
}
User Space
_______________________________________________________
Kernel Space
int open(char *_fileName, int mode)
{
......................................
......................................
push dword mode
push dword flags
push dword _fileName
mov eax, 5
add esp, byte 12
......................................
......................................
......................................
}
Difference between Library Functions and System Calls
- System calls
Generally performs an single specific operation
- Library Functions
May call system calls
May perform more than one task
More reliable than system calls
The relationship between system calls and library functions can be depicted as follows.
Library Functions | System Calls |
---|---|
fopen() | create(),open(),close() |
fclose() | read(),write() |
system() | chmod(),chown() |
malloc() | fork() |
getc() | unlink() |
Refer following web site for more C library functions.
Labels: