私のプロジェクトは、ほとんどの UNIX シェルと同様に、arglist を & で終了することにより、バックグラウンド処理を行う単純なシェル プログラムを実装することです。私の問題は、バックグラウンド処理で子プロセスを作成する必要がある場合に、GDB でシェルをデバッグする方法です。
私の子処理コードは次のようになります
int id;
int child=-1;
int running=0;
if ((strcmp(args[0], "&")==0){
if ((id==fork())==-1)
perror("Couldn't start the background process");
else if (id==0){ //start the child process
running++;
printf("Job %d started, PID: %d\n", running, getpid());
signal(SIGINT, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
execvp(args[0], args);
perror("Can't execute command);
exit(1);
else {
int jobNum= running-(running-1);
if ( (waitpid(-1, &child, WNOHANG) == -1)
perror("Child Wait");
else
printf("[%d] exited with status %d\n", jobNum, child>>8);
}
ps & などのコマンドを実行してブレークポイントを関数パーサーに設定しようとすると、ブレークポイントに到達せずにコマンドが実行されます。これは紛らわしく、このインスタンスではデバッガが役に立たなくなります。私はそれについて何ができますか?