대학 수업을위한 간단한 디버거를 만들고 있는데 SIGINT를 다루는 데 문제가 있습니다.SIGINT가 하위 프로세스로 보내지는 이유는 무엇입니까?
내가 원하는 것은 디버거 프로세스 (지금 PDB에서)가 SIGINT 신호를 자식 프로세스 (PDB에 의해 실제로 디버깅되고있는 프로세스)로 전달할 때입니다.
pid_t childid;
void catch_sigint(int sig)
{
signal(SIGINT,SIG_DFL);
kill(childid,sig);
}
int debuger (char *address, parm *vars)
{
int ignore=1;
int status;
childid = fork();
signal(SIGINT,catch_sigint);
if(childid==0)
{
ptrace(PTRACE_TRACEME,0, NULL,NULL);
if(execve(address,NULL,NULL)==-1)
{
perror("ERROR occured when trying to create program to trace\n");
exit(1);
}
}
else
{
int f_time=1;
while(1)
{
long system_call;
wait(&status);
if(WIFEXITED(status))break;
if(WIFSIGNALED(status))break;
system_call = ptrace(PTRACE_PEEKUSER,childid, 4 * ORIG_EAX, NULL);
if(!strcmp(vars->category,"process-control") || !strcmp(vars->category,"all"))
ignore = pr_calls(system_call,ignore,limit,childid,vars->mode); //function that takes the system call that is made and prints info about it
if(!strcmp(vars->category,"file-management") || !strcmp(vars->category,"all"))
ignore = fl_calls(system_call,ignore,limit,childid,vars->mode);
if(f_time){ignore=1;f_time=0;}
ptrace(PTRACE_SYSCALL,childid, NULL, NULL);
}
}
signal(SIGINT,SIG_DFL);
return 0;
}
이 프로그램 실행을하고 자식 프로세스를 포크하고 시스템 호출의 추적하는 프로그램을 간부 인 :
나는이 일을하고있다. 신호가 전혀 들리지 않으면 제대로 작동합니다.
그러나 추적 중에 Ctrl + C를 누르면 하위 프로세스가 멈추고 PDB가 계속 진행되고 중지 될 것으로 예상됩니다 (이 줄로 인해 if(WIFSIGNALED(status))break;
이 발생 함). 추적되는 프로그램은 시스템 호출을 계속합니다. . 인쇄
추적 프로그램입니다 :
#include <stdio.h>
int main(void)
{
for(;;) printf("HELLO WORLD\n");
return 0;
}
프로그램은
가 나는 또한 시스템의 ptrace은 C 후에 준다 호출 관찰 내가 Ctrl + C를 누르 후에도 HELLO WORLD 인쇄를 계속. trl + c는 -38이고 대기 상태는 1407 (정상 값이라고 생각합니다) 신호가 639로 변경된 후 한 번만 변경된 후 다음 대기 시간에 다시 1407로 변경됩니다.
그래서 내가 잘못하고있는 것은 무엇입니까?