2011-04-26 Low-level C programming revisited. Just some excercises for university, but they often provide good bases to go flying ... Take this code snippet: printf("parent\n"); fork(); printf("child\n"); It will print: parent child child But if you pipe the output through cat(1) it prints: parent child parent child Why? And this code: printf("parent "); fork(); printf("child\n"); will print: parent child parent child no matter if you pipe the output or not. This shows that you really should understand the facilities you use. In this case the buffering of stdio: Newline flushes the buffer if, and only if, it outputs to a terminal. I write these tiny excercise programs on some Sun workstations. They run SunOS 5.9 ... and have some strange keyboard layout. :-/ However, why not? As the programs I write are small, this is a nice opportunity to use ed(1) for it. I like ed but maintaining large source files with it is a pain, even for me. Those small programs, in contrast, are perfectly suited. But ... the version of ed they have on those systems is terrible. I always thought ed would be ed, but no, this one requires ending delimiter for regexps -- how unneccesary! And it doesn't under- stand: s,foo,bar (Note the missing last delimiter, causing the line to be printed afterwards.) Heirloom ed is luxury in contrast! Finally, Michi pointed this out to me: mkdir new cd new ls -a >foo What does `cat foo' print? Hint: You need to find the core of the question. Then think about fork(2) and exec(2) in some shell. http://marmaro.de/lue/ markus schnalke