# System call source code

**URL:** <https://community.unix.com/t/system-call-source-code/195407>\
**Category:** Programming\
**Created:** [May 2, 2008, 5:56am UTC](https://community.unix.com/t/system-call-source-code/195407 "2008-05-02T05:56:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramkrix](https://community.unix.com/letter_avatar/ramkrix/32/6_449c533f586939b6e5f246632a46421f.png) [@ramkrix](https://community.unix.com/u/ramkrix)\
**Post date:** [May 2, 2008, 5:56am UTC](https://community.unix.com/t/system-call-source-code/195407/1 "2008-05-02T05:56:05Z")

</div>

Hi,

1. Can anybode suggest me where to find the source code for system calls itself? Like open(), read(), close(). May I have the link or book where I can find the source code these functions itself?

2. When ever we quit a file or save and quit a file, the file content is stored in the disk. Internally, after putting the contents on the disk the kernal calls close() system call to close/quit the file. Am I right with what I said? please tell the alternative answer for what is happening inside on closing/quitting a file, if mine is wrong?

---

<div class="post-metadata">

**Author:** ![fabtagon](https://community.unix.com/letter_avatar/fabtagon/32/6_449c533f586939b6e5f246632a46421f.png) [@fabtagon](https://community.unix.com/u/fabtagon)\
**Post date:** [May 2, 2008, 6:14am UTC](https://community.unix.com/t/system-call-source-code/195407/2 "2008-05-02T06:14:16Z")

</div>

> [@](#):
>
> Can anybode suggest me where to find the source code for system calls itself?

Download the libc source code of the appropriate system. You'll find libc sources for Linux, bsd and Solaris on the net.

> [@](#):
>
> When ever we quit a file or save and quit a file,

Give some context. Quit and save aren't system calls either. Do you mean typical commands from the file menu? No. The application calls close(). The OS itsself takes care about writing the actual data to disk. Typically it won't write the contents to disk immediately but just send them to some buffer which is cleaned whenever the disk comes idle or the filesystem is unmounted.

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/6_449c533f586939b6e5f246632a46421f.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [May 2, 2008, 10:03am UTC](https://community.unix.com/t/system-call-source-code/195407/3 "2008-05-02T10:03:21Z")

</div>

IT would help a lot to know the UNIX you have.

---

<div class="post-metadata">

**Author:** ![shamrock](https://community.unix.com/letter_avatar/shamrock/32/6_449c533f586939b6e5f246632a46421f.png) [@shamrock](https://community.unix.com/u/shamrock)\
**Post date:** [May 2, 2008, 10:59am UTC](https://community.unix.com/t/system-call-source-code/195407/4 "2008-05-02T10:59:41Z")

</div>

If you like to read source code of the UNIX internals get [this book](http://www.amazon.com/Lions-Commentary-Unix-John/dp/1573980137).

---

<div class="post-metadata">

**Author:** ![Saurabh78](https://community.unix.com/letter_avatar/saurabh78/32/6_449c533f586939b6e5f246632a46421f.png) [@Saurabh78](https://community.unix.com/u/Saurabh78)\
**Post date:** [May 3, 2008, 4:02pm UTC](https://community.unix.com/t/system-call-source-code/195407/5 "2008-05-03T16:02:11Z")

</div>

If you are intrested to browse teh source code.  
Visit the soalris site  
[Search](http://cvs.opensolaris.org/source/)

---

<div class="post-metadata">

**Author:** ![gautamdheeraj](https://community.unix.com/letter_avatar/gautamdheeraj/32/6_449c533f586939b6e5f246632a46421f.png) [@gautamdheeraj](https://community.unix.com/u/gautamdheeraj)\
**Post date:** [May 5, 2008, 2:14am UTC](https://community.unix.com/t/system-call-source-code/195407/6 "2008-05-05T02:14:05Z")

</div>

For Code - you may use following link -  
[system.c](http://opengrok.netbsd.org/source/xref/lib/libc/stdlib/system.c)

For taking a look at what happens after close - take a look at  
[CodeIdol - Thinking about Advanced Programming in the UNIX Environment - File I O](http://codeidol.com/unix/advanced-programming-in-unix/File-I-O/)

---

<div class="post-metadata">

**Author:** ![era](https://community.unix.com/letter_avatar/era/32/6_449c533f586939b6e5f246632a46421f.png) [@era](https://community.unix.com/u/era)\
**Post date:** [May 5, 2008, 4:00am UTC](https://community.unix.com/t/system-call-source-code/195407/7 "2008-05-05T04:00:54Z")

</div>

System calls, by definition, are part of the operating system. If the source code for your operatnig system is available, you can download and browse it. Similarly for the C library, you can download the source for e.g. GNU glibc.

For more tutorial expositions, in addition to Lions, there's the BSD devil books (different books for [4.3BSD](http://www.amazon.co.uk/Implementation-Operating-Addison-Wesley-computer-science/dp/0201061961) and [4.4BSD](http://www.freebsd.org/doc/en/books/design-44bsd/)) and a book by [Plauger about the standard C library](http://www.amazon.com/Standard-Library-P-J-Plauger/dp/0131315099). Quick googling also brought up [The Linux Kernel: The Book](http://kernelbook.sourceforge.net/)
