I am trying make my own shell for my school homework, after the sucessfull fork call, I want to put pid which comes from fork() function into foreground and then I want to put my own shell into background. Then after the waitpid function, I need to my own shell into foreground again. For this I think like this:
if(tcsetpgrp(0, getpgid(pid))!=0)
perror("Foreground error: ");
waitpid(pid, NULL, 0);
if(tcsetpgrp(0, getpgid(shellpid))!=0)
perror("Foreground error: ");}
But after new process finishes, the linux shell stops my own shell. For instance, ls command is the new process in the picture. Please look at here: for terminal screen shot