Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't mangle memory for zombie processes #747

Merged
merged 2 commits into from Feb 11, 2024
Merged

Conversation

joske
Copy link
Collaborator

@joske joske commented Feb 2, 2024

On macOS, for a zombie process, proc_pidpath returns 0, and nothing is written in fullname, so it's uninitialized garbage. We should not try to do any string mangling on it.

There is no program name, and ps -ef returns <defunct> for the zombie, so I'm doing the same for btop.

for a zombie process, `proc_pidpath` returns 0, and nothing is written in fullname, so it's uninitialized garbage
@joske
Copy link
Collaborator Author

joske commented Feb 2, 2024

You can easily test this with the following little program that creates a zombie process:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

// This program creates a zombie process, the parent never calls wait()
int main() {
  int pid = fork();
  if (pid == 0) {
    exit(0);
  } else {
    printf("Child process: %d\n", pid);
    for (;;) {
      sleep(30);
    }
  }
  return 0;
}

Kill the parent to get rid of the zombie.

@aristocratos aristocratos merged commit 46f6b4f into main Feb 11, 2024
3 checks passed
@aristocratos aristocratos deleted the fix/zombie branch February 11, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants