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
.
source to share