1#include <stdio.h>
2#include <unistd.h>
3#include <sys/wait.h>
4
5volatile int release_child_flag = 0;
6
7int main(int argc, char const *argv[])
8{
9 pid_t child = fork();
10 if (child == -1)
11 {
12 perror(s: "fork");
13 return 1;
14 }
15
16 if (child > 0)
17 { // parent
18 if (argc < 2)
19 {
20 fprintf(stderr, format: "Need pid filename.\n");
21 return 2;
22 }
23
24 // Let the test suite know the child's pid.
25 FILE *pid_file = fopen(filename: argv[1], modes: "w");
26 if (pid_file == NULL)
27 {
28 perror(s: "fopen");
29 return 3;
30 }
31
32 fprintf(stream: pid_file, format: "%d\n", child);
33 if (fclose(stream: pid_file) == EOF)
34 {
35 perror(s: "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(stat_loc: &status);
42 if (wpid == -1)
43 {
44 perror(s: "wait");
45 return 5;
46 }
47 if (wpid != child)
48 {
49 fprintf(stderr, format: "wait() waited for wrong child\n");
50 return 6;
51 }
52 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
53 {
54 fprintf(stderr, format: "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(seconds: 1);
64
65 printf(format: "Child's previous process group is: %d\n", getpgid(pid: 0));
66 setpgid(pid: 0, pgid: 0); // Set breakpoint here
67 printf(format: "Child's process group set to: %d\n", getpgid(pid: 0));
68 }
69
70 return 0;
71}
72

source code of lldb/test/API/functionalities/process_group/main.c