次のコードは私のために働いており、要件を満たしているようです-
交流
#include<stdio.h>
int main()
{
int i=0;
printf("My PID is - %ld\n",getpid());
while(i>=0)
{
}
return 0;
}
Bc - プロセスの追跡
int main()
{
int pid;
int status;
struct user_regs_struct regs;
unsigned int eip;
printf("Enter pid to trace : \n");
scanf("%d",&pid);
printf("PID to be traced - %ld\n",pid);
ptrace(PTRACE_ATTACH,pid,0,0);
if(errno)
{
perror("attach");
return -1;
}
waitpid(pid,&status,WUNTRACED);
printf("Process Stopped\n");
while(1)
{
ptrace(PTRACE_GETREGS,pid,0,®s);
eip=ptrace(PTRACE_PEEKTEXT,pid,regs.eip,0);
printf("EIP - 0x%08x, instruction executed - 0x%08x\n",regs.eip,eip);
ptrace(PTRACE_CONT,pid,0,0);
waitpid(pid,&status,WUNTRACED);
}
return 0;
}
信号通過 -
kill -STOP 17779 kill -STOP 17779
Aの出力 -
xxxxx!xxxxx:~/myPer/stack_overflow [135]$ ./A
My PID is - 17779
Bの出力 -
XXXXX!xxxxx:~/myPer/stack_overflow [121]$ ./B
Enter pid to trace :
17779
PID to be traced - 17779
Process Stopped
EIP - 0x080483e1, instruction executed - 0x00f87d83
EIP - 0x080483e5, instruction executed - 0x00b8fa79
EIP - 0x080483e5, instruction executed - 0x00b8fa79
B がクライアントに配信された各シグナルの EIP 値を表示していることがわかります。基本的に、信号は A に配信されず、代わりに B がウェイクアップして EIP を調べ、ループを続行します。必要に応じて、シグナルを配信するようにコードを変更できます。
これはあなたの質問から私が理解したものです。何か他のことを理解した場合はお知らせください。それに応じて回答を更新します