void main()
{
putchar('a');
if (fork()) {
// parent process will run this code only
}
else
{
// forked child process will run this code only
}
}
[/code:1]
check u "man fork" u know why the code is like this.
the reason about the duplicate print out is that linux use buffered i/o. so that print "a' is still in buffer, so this is copied by child process as well. so child process will print thsi out. this is caused by glibc , not kernel.
u can trace the system call by "strace -f ./a.out" to see the system calls it use.
[quote:c8091e324f="yuchuan"]but what is glibc? does child must print contents of buffered i/o?is that a kink of initialization of child or buffer?
'mp3' is my classmate,and i introduced her here.we are doing linux experiments,so there are lots of difficulties.
i want u email very much.thx[/quote]
u had better find some document about unix programming to know more. The best is APUE (advanced programming in unix environment). there are chinese version in china, that book is very good.