Upcoming Posts

Upcoming Posts....

Make your own partition magic software.
How to make an assembler.
What is booting?
Write a simple OS!

‎"I have no special talents. I am only passionately curious." - Albert Einstein

Tuesday, April 17, 2012

What is System Call?

The system call is the fundamental interface between an application and the operating system's kernel. It is a way to requests a service like creating/opening file from the kernel.

1. System calls are not normal method calls. No libraries or header files are supplied by the OS. i.e. stdio.h is not provided by the OS. It's provided by the C/C++ language.
2. Usually System calls are not invoked directly, but rather via wrapper functions in glibc (or perhaps some other library).
3. Input or output parameters to System calls are copied to registers or pushed onto stack.
4. System calls are OS dependent. i.e. Two operating systems may not have same System calls.

Few System calls are as follows:

Process Control - load/execute/create/terminate process etc.
File management - create/delete/open/close/read/write file etc.
Device Management - request/release/read/write devices.



It is not possible to directly link (using any compiler) user-space applications with kernel space. For reasons of security and reliability, user-space applications must not be allowed to directly execute kernel code or manipulate kernel data.


Instead, the kernel must provide a mechanism by which a user-space application can "signal" the kernel that it wishes to invoke a system call. The application can then trap into the kernel through this well-defined mechanism, and execute only code that the kernel allows it to execute. The exact mechanism varies from architecture to architecture.


Typically, System calls are implemented as software interrupt or trap. Nowadays, additional techniques like SYSCALL/SYSENTER, SYSRET/SYSEXIT (the two mechanisms were independently created by AMD and Intel, respectively), is being used.

Generally, System calls are not invoked directly, but rather via wrapper functions in glibc (or perhaps some other library). Why? Because System calls are OS dependent. Making direct System calls from the program will make it non-portable. Instead, we should call wrapper methods/API provided by Standard C/C++ libs.


Let's take an example, you'd like to create a new file and want to write your name to the file. You'll write the following C program:

#include
#include "input.c"

int main(void)
{
char name[64] = "Dew Kumar";
 FILE *playerdata;

playerdata = fopen(name, "W+"); /*create the new file*/
fgets(name,buffer,playerdata); /*write the players name to the file*/
fclose(playerdata); /*close the file*/
}

Here, fopen(), fgets() and fclose() are the library method/API which calls System call to open/write/close files.

Reference: http://en.wikipedia.org/wiki/System_call

16 comments:

  1. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
    Digital Marketing Training in Bangalore

    ReplyDelete
  2. Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your websit
    full Stack developer Training in Bangalore

    ReplyDelete
  3. Awesome article. It is so detailed and well formatted that i enjoyed reading it as well as get some new information too.
    Click here:
    python training institute in chennai
    Click here:
    python training in chennai

    ReplyDelete
  4. I read this post two times, I like it so much, please try to keep posting & Let me introduce other material that may be good for our community.
    Blue Prism Training in Pune

    Blueprism training in tambaram

    Blueprism training in annanagar

    ReplyDelete
  5. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.

    angularjs Training in bangalore

    angularjs Training in btm

    angularjs Training in electronic-city

    angularjs online Training

    angularjs Training in marathahalli

    ReplyDelete
  6. Read all the information that i've given in above article. It'll give u the whole idea about it.
    python course in btm | python Course in marathahalli| python training institute in jayanagar

    ReplyDelete
  7. Really impressed! Everything is very open and very clear clarification of issues. It contains true facts. Your website is very valuable. Thanks for sharing.
    data analytics courses in hyderabad with placements

    ReplyDelete
  8. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.data science course business analytics course in kanpur

    ReplyDelete