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

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

 

parent.c

child.c

Log from versions:
parent.c:	if(0 /* amode == O_RDONLY */) {
child.c:     for (counter = 0; counter < MAX_LOOPS; counter++)
        {
#if 0
        printf("\nchild: counter %d", counter);
#else
        nbytes = read(stdin, readbuffer, sizeof(readbuffer));

--
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: nbytes: -1
child: nbytes: -1
child: nbytes: -1
child: nbytes: -1
child: nbytes: -1
child: nbytes: -1
child: nbytes: -1
child: nbytes: -1
child: nbytes: -1
child: nbytes: -1
child process exiting
Log from versions:
parent.c:	if(1 /* amode == O_RDONLY */) {
child.c:     for (counter = 0; counter < MAX_LOOPS; counter++)
        {
#if 1
        printf("\nchild: counter %d", counter);

--

parent starting
vread: retfd 3, childfd 4, childrw 1

parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
reap_childs end
parent: read stuff from child: [
child process running
child: counter 0
child: counter 1
child: counter 2
child: counter 3
child: counter 4
child: countŔ˙ ┐╦9@], nbytes: 120
parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
parent: read stuff from child: [er 5
child: counter 6
child: counter 7
child: counter 8
child: counter 9
child process exiting
d: counter 4
child: countŔ˙ ┐╦9@], nbytes: 95
parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
parent: read stuff from child: [], nbytes: 0
parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
parent: read stuff from child: [], nbytes: 0
parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
parent: read stuff from child: [], nbytes: 0
parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
parent: read stuff from child: [], nbytes: 0
parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
parent: read stuff from child: [], nbytes: 0
parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
parent: read stuff from child: [], nbytes: 0
parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
parent: read stuff from child: [], nbytes: 0
parent: wrote stuff to child, nbytes: -1
parent: trying to read from child...
parent: read stuff from child: [], nbytes: 0
parent returning