sorry, I was watching TV just now

lumlumq (lumlum)
emm..... I would give you 75
out of 100 for your code.

The basic infrastructure was right, but there are two fatal errors.
1) A pipe can only be used to either read or write by a process, but not
both, otherwise, you would confuse the STREAMS(although it's not
gonna crash). so the parent process should have used the fd[1]
to write , and the child process should have used the fd[0] to read.

2) It's very important that you close the other descriptor that you don't
need, otherwise you would never know when the other side closes
the connection, because you always have a connection open to
yourself, the read() function will return zero on a reading end of
pipe only when all connections to the writing end have been closed.

I'm going to the picnic on Saturday, see you then...
2001-4-13 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: a typical unix interview question

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论