×

Loading...

lumlum....... I have to surrender, I must fail at the interview, anyway, I want to know the right answer. :-(

flying_snow (飞雪浮冰)
about No.2:
#include "unpipc.h"
main(int argc, char **argv)
{
int fd[2], n;
char c;
pid_t childpid;

Pipe( fd );
if ( ( childpid = Fork( ) ) == 0 )
{
sleep( 3 );
if ( ( n = Read( fd[0], &c, 1 ) ) != 1 )
err_quit( "child: read returned %d", n );
printf( " child read %c\n", c);
Write( fd[0], "C", 1 )
exit( 0 );
}
Write( fd[1], "P", 1);
if ( ( n = Read( fd[1], &c, 1) ) != 1 )
err_quit( "parent: read returned %d", n );
printf( " parent read %c\n", c);
exit( 0);
}

Is it correct? Please give me a right answer, thank you! :-)
(#45007@0)
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技术讨论