06-10-06 06:21 PM
The file descriptor isn't incremented till just before write() returns.
anoop.vijayan@gmail.com wrote:
> #include <sys/types.h>
> #include <unistd.h>
> #include <stdio.h>
>
> int main()
> {
> pid_t pid=fork();
> if ( pid == 0 )
> {
> write(1,"I am Child",10);
> fflush(stdout);
> _exit(0);
> }
> else if (pid > 0)
> {
> write(1,"I am Parent",11);
> fflush(stdout);
> exit(0);
> }
> else
> {
> printf("fork failed");
> }
> }
>
> now, if i run ./a.out > op, in a multiprocessor system, the content of
> the file is
> I am Childt
>
> Note the 't' at the end of the string. Its obvious that parent data was
> overwritten by child.
> I want to know if this behaviour is as per UNIX standards.
>
> Thanks
> anoop
[ Post a follow-up to this message ]
|