How to implement shell control

Hi guys, I am using C ++ to implement a linux shell, but I have some signal problem.

Here is the basic logic of my shell, this is pseudocode, but you can easily find out what I want to do.

signal_handler(int sig){
  switch(sig){
    case SIGINT: ... break;
    case SIGTSTP: ... break;
  }
}

main{
  signal(SIGINT,SIG_IGN);
  signal(SIGTSTP, SIG_IGN);

  what main process do{
    wait(&child_pid);
  }
  what child process do{
    signal(SIGINT, signal_handler);
    signal(SIGTSTP, signal_handler);
  }
}

      

I am currently using wait(&fpid)

to wait for the child process to finish. But now I want to create a job management function. What signals should I encode for waitpid?

I am using SIG_IGN

to make the main process of this shell ignore the signal ctrl-c

and ctrl-z

, which is equal to SIGINT

and SIGTSTP

.

+3


source to share


1 answer


you need to create a signal_handler for the main process that can take a signal ctrl-c

and ctrl-z

then pass the signal to the child process.



This means that the signal handler for the main process and the child process must be different.

0


source







All Articles