Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwang200099 authored Jul 13, 2020
1 parent b1bcaa4 commit 275e044
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Bonus-1-daemon/daemon/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_SRC_FILES := daemon.c
LOCAL_MODULE := daemon
LOCAL_CFLAGS += -pie -fPIE
LOCAL_LDFLAGS += -pie -fPIE
LOCAL_FORCE_STATIC_EXECUTABLE := true
include $(BUILD_EXECUTABLE)
32 changes: 32 additions & 0 deletions Bonus-1-daemon/daemon/jni/daemon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*this program create a daemon process,
which will make OOM_killer awaken periodically for some pre-set period T
*/
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#define T 2


int main(void)
{
if(daemon(0,0) == -1)
{
printf("fail to create daemon process\n");
exit(EXIT_FAILURE);
}

while(1)
{
//use system call 384, which is oom_killer to check
//if a user has run out its memory quota.
//If that, then it will kill the process that has the highest RSS
//among all processes belonging to the user.
//syscall(383,10070,100000000);
syscall(378);
sleep(T);
}
return 0;
}

0 comments on commit 275e044

Please sign in to comment.