Showing posts with label system programming. Show all posts
Showing posts with label system programming. Show all posts

12 October 2010

The differences between write() and C library IO functions?

write() is a system call, the strings or characters it writes doesn't get buffered by a user-space buffer. C library IO functions like fputs() ,fprintf() or puts() is user space code; all the data they write is written to a user space buffer (you don't notice this if all you are writing is user space codes, if you are doing system programming with some user space codes you will find that the data actually gets buffered). To make such data out of buffer, use fflush(). Check the man page of fflush() yourself.

17 September 2010

Caution when redirecting stdin/stdout/stderr in C

You must save the original preopened file descriptors using dup(). You then use dup2(), open() to do IO redirection. After done with IO redirection, you need to restore default stdin/stdout/stderr using sdup2() again, otherwise you program cannot interact with STDIO properly as it could before IO redirection! The previous article on this blog shows a good code example on how to do that.

15 September 2010

Important concepts about Unix Pipes architectures

  • UNIX pipe concepts

    • One important thing to note here is that each process in the pipeline is a child of the original child of the shell (pid 202)

    • They are not children of each other the further down the pipeline we go

    • Another thing to note is that only the shell (process 163) executes a wait. All the others simply die after they exec their respective command

Posted from Diigo. The rest of my favorite links are here.