<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/112173>112173</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
lldb: inconsistent result using follow fork mode
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
tony-go
</td>
</tr>
</table>
<pre>
Hey team 👋🏼
I hope you are doing great 😄
I try to do some experiments with `dlsym`/`fork` and how the follow fork mode react to it.
Here is my C program:
```c
#include <dlfcn.h>
#include <stdio.h>
#include <unistd.h>
typedef int (*fork_func_t)(void);
int main() {
printf("start process pid: %d\n", getpid());
fork_func_t fork = dlsym(RTLD_DEFAULT, "fork");
if (NULL == fork) {
printf("fork symbol not found!\n");
return 1;
}
int pid = fork();
if (pid != 0) {
if (pid > 0) {
printf("exit parent process\n");
}
if (pid == -1) {
printf("fork failed\n");
}
return 0;
}
printf("continue execution for pid`: %d\n", getpid());
// wait for 10 seconds before exit
sleep(10);
printf("exit child process from pid: %d\n", getpid());
return 0;
}
When I run on LLDB I have this:
```
(lldb) run
Process 86557 launched: '.../anti-debug/c/build/antidebug' (arm64)
start process pid: 86557
exit parent process
continue execution for pid`: 86561
Process 86557 exited with status = 0 (0x00000000)
```
Either it waits for 10 seconds (due to `sleep`) and display `Process 86557 exited with status = 0 (0x00000000)`, or it directly display the `Process 86557 exited with status = 0 (0x00000000)`.
In both cases I never saw the printed string `exit child process from pid: %d\n`.
It is probably an issue from my code (maybe due how to `sleep` works) rather than with LLDB, but I guess that it is a really good opportunity to learn how stuff works under the hood :)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVk1v2zgQ_TX0ZRCDomxZPvjgxDEaIFgsFi32WFDiyOKWIgVymFT_fkHadR3H3RbdIFAUDmfe4-N8SIagDxZxw5b3bLmbyUi98xtydro7uFnj1LT5gBMQygHYnrP1nq0LVt-f3us9u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