Reputation: 41
I am trying to check memory leaks on a C program containing child processes using the "leaks -atExit -- ./PROGRAM_NAME" command. Note that the program returns normally when executed on its own. The leaks command fails to return when the program contains the waitpid() function. Why?
Below is a minimal code example that generates the behavior. Thanks for your help.
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
int main()
{
pid_t pid;
pid = fork();
if (pid == -1)
{
printf("Fork error\n");
exit(EXIT_FAILURE);
}
if (pid == 0)
{
printf("Hello from the child process\n");
exit(EXIT_SUCCESS);
}
printf("Hello from the parent process\n");
if (waitpid(pid, NULL, 0) == -1)
{
printf("Waitpid error\n");
exit(EXIT_FAILURE);
}
printf("Child process finished\n");
return (0);
}
Upvotes: 3
Views: 430