-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add contrib/membomb/membomb.subthread
When the main thread exits, the whole process becomes invisible to earlyoom. This is no good. Relates-to: #309
- Loading branch information
Showing
4 changed files
with
44 additions
and
3 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
/membomb | ||
/membomb.subthread |
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 |
---|---|---|
@@ -1,4 +1,14 @@ | ||
CFLAGS += -Wall -Wextra -g -fstack-protector-all -std=gnu99 | ||
|
||
membomb: $(wildcard *.c *.h) Makefile | ||
$(CC) $(CFLAGS) -o $@ $(wildcard *.c) | ||
.PHONY: all | ||
all: membomb membomb.subthread | ||
|
||
membomb : $(wildcard *.c *.h) Makefile | ||
$(CC) $(CFLAGS) -o $@ eat_all_memory.c membomb.c | ||
|
||
membomb.subthread: $(wildcard *.c *.h) Makefile | ||
$(CC) $(CFLAGS) -lpthread -o $@ eat_all_memory.c membomb.subthread.c | ||
|
||
.PHONY: format | ||
format: | ||
clang-format --style=file -i *.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
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,30 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
/* In a subthread, eat up all memory. | ||
* The main thread exits and will show up as a zombie. | ||
* | ||
* This file is part of the earlyoom project: https://github.com/rfjakob/earlyoom | ||
*/ | ||
|
||
#define _GNU_SOURCE | ||
|
||
#include <pthread.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
|
||
#include "eat_all_memory.h" | ||
|
||
void* eat_all_memory_thread(__attribute__((__unused__)) void* arg) | ||
{ | ||
printf("sub thread = pid %d\n", gettid()); | ||
eat_all_memory(); | ||
return NULL; | ||
} | ||
|
||
int main() | ||
{ | ||
printf("main thread = pid %d\n", gettid()); | ||
pthread_t thread; | ||
pthread_create(&thread, NULL, &eat_all_memory_thread, NULL); | ||
pthread_exit(NULL); | ||
} |