小编Jul*_*nRC的帖子

C - 使用ptrace和waitpid进行分段错误

对于C语言中的实验学校,我们必须编写一个进程(我们将称之为A),需要连接到另一个进程(B)并在函数中放置一个陷阱(陷阱指令是0xCC),所以我们做了但是当B输入是这个函数时,我们有一个分段错误

所以这是附加到其他进程的进程A.

#include <stdio.h>
#include <stdlib.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>

int main(int argc, char *argv[]) {

pid_t pidTargetProgram;
FILE *file;
int buf;
char path[50];
long long int address;


if (argc == 2) {
   fprintf(stderr, "Argument waited !\n");
   exit(1);
 }

// The second argument is the PID of the program 
pidTargetProgram = atoi(argv[1]);

// The third argument is the address of the function where we are going to put a trap
address = strtoll(argv[2], NULL, 16);

// …
Run Code Online (Sandbox Code Playgroud)

c segmentation-fault

4
推荐指数
1
解决办法
236
查看次数

标签 统计

c ×1

segmentation-fault ×1