[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Backround process, fork & vfork, synchronization methods?



I made a modification to child.c:

#if 0
        nbytes = read(stdin, readbuffer, sizeof(readbuffer));
        if (nbytes > 0)
#else
        if ( fgets(readbuffer, sizeof(readbuffer), stdin) )
#endif

I managed to read stuff from child with this fgets. However, the
behaviour differs between standard Linux and ELinux. (See attached
logs log5_linux.txt and log5_elinux.txt). Parent process seems not
to be able to read stuff back from child process. And in standard
Linux version the process context switch seems to happen after parent
process has exited, if printf output is correct. 

I am obviously still doing something wrong here. I think I still
should use the read() function in child.c instead of fgets, because
I don't won't waiting for piped message to block, my child and parent
processes have also other things to do.

BR,
Timo

> -----Original Message-----
> From: Timo.Sakari@xxxxxxx.fi">mailto:Timo.Sakari@xxxxxxx.fi]
> Sent: 20. maaliskuuta 2001 20:41
> To: bjorn.wesen@xxxxxxx.com
> Subject: RE: Backround process, fork & vfork, synchronization methods?
> 
> 
> > From: Bjorn Wesen [mailto:bjorn.wesen@xxxxxxx.com]
> 
> > yes they can, do pipe() before the vfork/exec and make sure 
> > the child gets
> > one part of the pipe as its stdin/stdout.
> > for example (from our sftpd.c)
> 
> I made my own application based on your sftpd.c, and managed to get
> parent process successfully start a child process. (See attachments
> parent.c and child.c). I want to have two way communication between
> parent and child (read and write to/from parent and child), but
> so far I have only succeeded from writing from child to parent.
> (See attached files log3.txt and log4.txt)
> 
> I am propably doing something wrong here, but I cannot pinpoint
> the error in my codes. Any help making this communicating 
> between these
> two processes two-way, would be greatly appreciated.
> 
> BR,
> Timo
> 
>  
> 
> 

Standard Linux:

parent starting
vwrite: retfd 4, childfd 3, childrw 0

parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent returning

child process running
child received: [parent: counter: 0
]
child received: [parent: counter: 1
]
child received: [parent: counter: 2
]
child received: [parent: counter: 3
]
child received: [parent: counter: 4
]
child received: [parent: counter: 5
]
child received: [parent: counter: 6
]
child received: [parent: counter: 7
]
child received: [parent: counter: 8
]
child received: [parent: counter: 9
]
child process exiting
ELinux:

parent starting
vwrite: retfd 6, childfd 5, childrw 0

parent: wrote stuff to child, nbytes
child process running
child received: [parent: counter:: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes 0
]
child received: [parent: counter: 1: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes
]
child received: [parent: counter:: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes 2
]
child received: [parent: counter: 3: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes
]
child received: [parent: counter:: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes 4
]
child received: [parent: counter: 5: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes
]
child received: [parent: counter:: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes 6
]
child received: [parent: counter: 7: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent: wrote stuff to child, nbytes
]
child received: [parent: counter:: 19
parent: trying to read from child...
parent: read stuff from child: [], nbytes: 8
]
child received: [parent: counter: 9 -1
parent: wrote stuff to child, nbytes
]
child process exiting
: 19
reap_childs end
parent: trying to read from child...
parent: read stuff from child: [], nbytes: -1
parent returning