Skip to content

Commit

Permalink
Add contrib/membomb/membomb.subthread
Browse files Browse the repository at this point in the history
When the main thread exits, the whole process becomes invisible
to earlyoom. This is no good.

Relates-to: #309
  • Loading branch information
rfjakob committed Mar 15, 2024
1 parent 4f61e84 commit 6c0f54f
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
1 change: 1 addition & 0 deletions contrib/membomb/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/membomb
/membomb.subthread
14 changes: 12 additions & 2 deletions contrib/membomb/Makefile
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
2 changes: 1 addition & 1 deletion contrib/membomb/membomb.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* Use up all memory that we can get, as fast as we can.
* As progress information, prints how much memory we already
* have.
*
*
* This file is part of the earlyoom project: https://github.com/rfjakob/earlyoom
*/

Expand Down
30 changes: 30 additions & 0 deletions contrib/membomb/membomb.subthread.c
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);
}

0 comments on commit 6c0f54f

Please sign in to comment.