Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

According to this question, a good way to learn system programming would be to implement the existing tools. I decided to try to rewrite ls and ps.

My question is how would one proceed to get documentation for such?

  • Where can I find the API of system calls needed to query the kernel, the file system, etc ...

  • I thought that maybe I could take a look at the source code of the GNU tools. Where can I find it?

  • Are there any (hopefully freely available online) good documentation you guys would recommend as to where to start?

share|improve this question
add comment

2 Answers 2

up vote 7 down vote accepted

You can use the Glibc manual as a reference. It's not for absolute beginners, but if you're reasonably fluent in C you should be able to read a section and write a working program.

You can find the source of the GNU tools on the GNU website; the easiest way to get it is to obtain the source packages on your Linux distribution (e.g. apt-get source coreutils if your distribution uses Debian packaging utilities). I recommend starting with BusyBox rather than the GNU tools. BusyBox is a set of utilities for embedded Linux systems; it's smaller and simpler than the GNU utilities.

You can run strace ls to see what system calls ls is making. Note that when you write a program, you don't call system calls directly, you call functions in the C library which make system calls. For things like file manipulations, the C library functions like open and read are pretty close to the system calls though.

For learning, a book (on paper) is usually helpful. Advanced Programming in the UNIX® Environment (APUE) is a classic. If you get it, make sure to get the second edition, as the first is quite dated. This book is the reference, but other books may be more suitable for beginners; shop around.

share|improve this answer
    
Thank you for a great answer! –  rahmu Oct 3 '11 at 17:47
add comment

On linux, commands as ps,free and top are implemented reading information from proc file-system.

   The proc file system is a pseudo-file system which is used as an inter-
   face to kernel data structures.  It is commonly mounted at /proc.  Most
   of  it  is  read-only,  but  some  files  allow  kernel variables to be
   changed.

Start at man 5 proc and do not forget that all these utilities are open-source, so you can also peek they code.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.