1 #include <stdio.h> 2 #include <unistd.h> 3 #include <sys/wait.h> 4 5 volatile int release_child_flag = 0; 6 7 int main(int argc, char const *argv[]) 8 { 9 pid_t child = fork(); 10 if (child == -1) 11 { 12 perror("fork"); 13 return 1; 14 } 15 16 if (child > 0) 17 { // parent 18 if (argc < 2) 19 { 20 fprintf(stderr, "Need pid filename.\n"); 21 return 2; 22 } 23 24 // Let the test suite know the child's pid. 25 FILE *pid_file = fopen(argv[1], "w"); 26 if (pid_file == NULL) 27 { 28 perror("fopen"); 29 return 3; 30 } 31 32 fprintf(pid_file, "%d\n", child); 33 if (fclose(pid_file) == EOF) 34 { 35 perror("fclose"); 36 return 4; 37 } 38 39 // And wait for the child to finish it's work. 40 int status = 0; 41 pid_t wpid = wait(&status); 42 if (wpid == -1) 43 { 44 perror("wait"); 45 return 5; 46 } 47 if (wpid != child) 48 { 49 fprintf(stderr, "wait() waited for wrong child\n"); 50 return 6; 51 } 52 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) 53 { 54 fprintf(stderr, "child did not exit correctly\n"); 55 return 7; 56 } 57 } 58 else 59 { // child 60 lldb_enable_attach(); 61 62 while (! release_child_flag) // Wait for debugger to attach 63 sleep(1); 64 65 printf("Child's previous process group is: %d\n", getpgid(0)); 66 setpgid(0, 0); // Set breakpoint here 67 printf("Child's process group set to: %d\n", getpgid(0)); 68 } 69 70 return 0; 71 } 72