-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Evaluating valgrind in multiprocess scenarios
- Loading branch information
Shrinivas Kamath
committed
Aug 3, 2017
1 parent
ef464a3
commit d44cb96
Showing
5 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
cmake_minimum_required (VERSION 2.8.11) | ||
|
||
set (CMAKE_BUILD_TYPE Debug) | ||
# Add -O0 to remove optimizations when using gcc | ||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0") | ||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") | ||
|
||
add_executable (parent parent.c) | ||
add_executable (childA childA.c) | ||
add_executable (childB childB.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
RUNNING WITH VALGRIND | ||
===================== | ||
|
||
mkdir -p build | ||
cd build; cmake ..; make | ||
valgrind --trace-children=yes --leak-check=full --show-reachable=yes --error-limit=no --log-file=valgrind.log ./parent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
#define WELCOME_MSG "Hello, from child A\n" | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
char *str = strdup (WELCOME_MSG); | ||
|
||
printf ("%s", str); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdio.h> | ||
|
||
int main (int argc, char *argv[]) | ||
{ | ||
int i = 0; | ||
printf ("Hello, from child A\n"); | ||
|
||
while (i < argc) { | ||
printf ("%s\n", argv[i]); | ||
i++; | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <sys/wait.h> | ||
#include <string.h> | ||
|
||
#define PARENT_MEM_LEAK | ||
|
||
#define WELCOME_MSG "Hello, World\n" | ||
|
||
void launch(char *app) | ||
{ | ||
pid_t pid; | ||
|
||
if ((pid = fork()) == 0) { | ||
/* child */ | ||
execl(app, app, NULL); | ||
perror ("app spawn failed\n"); | ||
} else { | ||
/* parent, wait for child to exit */ | ||
int status = 0; | ||
waitpid(pid, &status, 0); | ||
} | ||
} | ||
|
||
int main( void ) | ||
{ | ||
#ifdef PARENT_MEM_LEAK | ||
char *c = strdup (WELCOME_MSG); | ||
#else | ||
char *c = WELCOME_MSG; | ||
#endif | ||
printf ("%s", c); | ||
launch ("childA"); | ||
} |