[Lldb-commits] [lldb] Fix lldb crash while handling concurrent vfork() (PR #81564)

Greg Clayton via lldb-commits lldb-commits at lists.llvm.org
Tue Feb 13 12:53:47 PST 2024


================
@@ -0,0 +1,45 @@
+#include <iostream>
+#include <thread>
+#include <unistd.h>
+#include <vector>
+
+int call_vfork() {
+  printf("Before vfork\n");
+
+  pid_t child_pid = vfork();
+
+  if (child_pid == -1) {
+    // Error handling
+    perror("vfork");
+    return 1;
+  } else if (child_pid == 0) {
+    // This code is executed by the child process
+    printf("Child process\n");
+    _exit(0); // Exit the child process
+  } else {
+    // This code is executed by the parent process
+    printf("Parent process\n");
----------------
clayborg wrote:

Add the pid to the global vector:
```
printf("Parent process\n");
std::lock_guard<std::mutex> Lock(g_child_pids_mutex);
g_child_pids.append(child_pid);
```

https://github.com/llvm/llvm-project/pull/81564


More information about the lldb-commits mailing list