×

Loading...

Topic

This topic has been archived. It cannot be replied.
  • 工作学习 / IT技术讨论 / a typical unix interview question
    Guys, motivated by the previous discussion on unix C, which was reminiscent of those good old days when I worked on Unix., here I give you guys a couple of more typical interview questions I used to ask at interviews:

    1) how to create a daemon process
    2)How do you achieve interprocess communication(IPC), give me
    an example to illustrate how you can use unamed pipe to make two
    processes talk.
    3)What is the difference between kernel and user threads?

    .... list goes on..
    • 我还以为lumlum去了窝太滑得到武林密笈了, 几个月不见成了旷世高手. Anyway, welcome on board and thanks for the contribution. I suggest you using "numnum" instead of "lumlum".
      • hehe, sorry for confusion, pal..I was just too lazy to sign off, and she doesn't bother to sign back on if I have signed her off. see you on Saturday
    • lumlum....... I have to surrender, I must fail at the interview, anyway, I want to know the right answer. :-(
      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! :-)
      • sorry, I was watching TV just now
        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.

        -15
        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.
        -10

        I'm going to the picnic on Saturday, see you then...
        • 哈哈!第一个致命错误是我的笔误,真糟糕,手指一抖,0变1了 :-)
          还有,为什么跟帖不多?是不是都是WINDOWS程序员,而搞UNIX的很少呢?据我所知UNIX下的工作机会很多呀,怎么没有人感兴趣呢?
    • I hope meet you soon, actually I met problem in my project recently. I need your help! :-)
      • Yard! Buddy, I am sure you can get help from him!
    • Hi,在哪都能见到你。您是做哪行的,怎么什么都知道?希望有机会能认识一下。Thank you!
    • lumlum...do you know how to write a hardware driver on sco unix? i have some question. could u help me?