20 thoughts on “Lab 4

  1. Hi Professor, I’ve encountered some trouble after trying to install the readline library.

    After doing make, I get this:
    /usr/local/lib/libreadline.so: undefined reference to `PC’
    /usr/local/lib/libreadline.so: undefined reference to `tgetflag’
    /usr/local/lib/libreadline.so: undefined reference to `tgetent’
    /usr/local/lib/libreadline.so: undefined reference to `UP’
    /usr/local/lib/libreadline.so: undefined reference to `tputs’
    /usr/local/lib/libreadline.so: undefined reference to `tgoto’
    /usr/local/lib/libreadline.so: undefined reference to `tgetnum’
    /usr/local/lib/libreadline.so: undefined reference to `BC’
    /usr/local/lib/libreadline.so: undefined reference to `tgetstr’
    collect2: ld returned 1 exit status

    How do I fix it?

    Thank you!

    • Looks like ncurses is not linked. What platform are you using?

      You can fixed this by changing the Makefile to append “-lncurses” after “-lreadline” (without the quotes).

  2. Personally I feel that a useful command to test lab04 would be the sleep command. Since it’ll terminate by itself after x seconds, you wont have to worry about manually killing your orphaned process.

  3. Dear Professor Ooi,

    How can we check no-child-left-behind policy in the case when command == NULL?
    I try typing Ctrl + C. However, in fact, Ctrl + C will kill the process bush as well as its child processes even when I add nothing to the part of the source code which handles the case command == NULL.

    • Hi Duy, the shortcut should be Control-D, not Control-C.

      From man page of readline: “readline returns the text of the line read. A blank line returns the empty string. If EOF is encountered while reading a line, and the line is empty, NULL is returned.”

      How to generate EOF? From Lab 4: “User may enter a special command exit or the EOF character (Control-D) at the prompt, upon which the shell exits normally.”

      • Thanks Prof. I think I overlooked that part.
        By the way, can I change your source code a little bit? It is because I think the ways we handle the case command == null and command “==” “exit” are the same. Thus, I want to combine them as follows: if(command == null || strcmp(command, “exit”) == 0) { // Handle those cases };

  4. Dear Prof,

    When I launch a program in the background, it will be followed by a blank line. The $ bush prompt will not appear immediately, even though its actually parsing for the next command.

    In your demo, the $ bush appears immediately.

    Do I need to fix this? Any suggestions as to how to fix this regardless of whether its required?

        • I did not deal with it as well. Just that on my (virtual) machine, it happens to work OK when I record the video.

          Dealing with this properly would require job control and terminal control, which is beyond the scope of CS2106.

  5. Hi Mr Ooi Wei Tsang,

    When I try to do the background command, I always get this problem, $bush appears before the output of the child process:

    $bush who &
    $bush user82 pts/1 ……

    Do I need to work on it to change it?

    For the child process loop, do I have to kill it after I type in exit to get out of bush?

    Thank you!

  6. Dear Prof.
    I use prctl(PR_SET_PDEATHSIG, SIGHUP); and check if (getppid() == 1) kill(getpid(),SIGHUP) then all the child processes will be killed after the parent die

Leave a Reply

Your email address will not be published. Required fields are marked *