Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

C Shell Questions

Greetings all,

I've been tasked to create a C shell for one of my classes at school. At this time, I am able to execute generic commands in my shell. For examples: ls -al, mv, cp, cd, pwd, etc all work. But it is time to work on the more difficult parts of the assignment. I have been in structured that I am supposed to be able to handle the 'bg' and 'fg' commands.

I am not sure where to begin on this. Perhaps someone can point me in the right directions. I shall, for you, write down my thoughts about this:

In my shell, if the user types program &, it shall start it in the bg list. Now, this means, that, I will fork off the new program. Then, I must place it in the background list and return control to the shell. Then, when the user types fg jobid, it will switch the terminal to the indicated job. I do not know how to place the program into the bg list, or even what to place in the list. The PID? Some sort of reference?? With fg, how do I switch control from the bg process and make it take control of stdin or the terminal in general?

The jobs command also does not report the bg jobs if it is started with 'program &' in my command line.

As one can see, I do not know where to really begin.

Thank you for the assistances.

Comments

  • IDKIDK Member Posts: 1,784
    : Greetings all,
    :
    : I've been tasked to create a C shell for one of my classes at
    : school. At this time, I am able to execute generic commands in my
    : shell. For examples: ls -al, mv, cp, cd, pwd, etc all work. But it
    : is time to work on the more difficult parts of the assignment. I
    : have been in structured that I am supposed to be able to handle the
    : 'bg' and 'fg' commands.
    :
    : I am not sure where to begin on this. Perhaps someone can point me
    : in the right directions. I shall, for you, write down my thoughts
    : about this:
    :
    : In my shell, if the user types program &, it shall start it in the
    : bg list. Now, this means, that, I will fork off the new program.
    : Then, I must place it in the background list and return control to
    : the shell. Then, when the user types fg jobid, it will switch the
    : terminal to the indicated job. I do not know how to place the
    : program into the bg list, or even what to place in the list. The
    : PID? Some sort of reference?? With fg, how do I switch control from
    : the bg process and make it take control of stdin or the terminal in
    : general?
    :
    : The jobs command also does not report the bg jobs if it is started
    : with 'program &' in my command line.
    :
    : As one can see, I do not know where to really begin.
    :
    : Thank you for the assistances.
    :

    With command& you should redirect that input/output to a wrapper that redirects its output and input to nothing. Then when you fg, you tell the wrapper to redirect to the terminal.

    I have no idea how to design a wrapper but you could look at the source of the original c shell maybe...

    This is very related to the command | command structure.

    You talk about the bg list, is it your own bg list? or is it a unix bg list you're talking about?

    I really don't know much, but any help is better than none...
Sign In or Register to comment.