From: 羅秉鈞 <luo...@gm...> - 2012-06-27 09:52:38
|
Dear All, fork12 test forks as many child process as possible until the system out of memory. And kernel OOM killer is triggered to select candidate process to be killed. fork12 expected one of its forked child process to be chosen, but what if any other process is chosen. Even the worst, shell script("/bin/sh") or parent process was chosen to be killed. No way return and the system really crashed. But this is not what fork12 wants. I proposed the solution for this is disable the OOM killer of parent process and adjust child process's oom_score_adj to 500(or any other number larger than 0), this purpose just to make child process can be easily chosen. Do you have better idea? Thank you. -------------------------------------------------------------------------------------------- From: Luo,BingJiun <bj...@fa...> --- .../testcases/kernel/syscalls/fork/fork12.c | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/ltp-full-20120401/testcases/kernel/syscalls/fork/fork12.c b/ltp-full-20120401/testcases/kernel/syscalls/fork/fork12.c index d052fba..c3d7cb5 100644 --- a/ltp-full-20120401/testcases/kernel/syscalls/fork/fork12.c +++ b/ltp-full-20120401/testcases/kernel/syscalls/fork/fork12.c @@ -63,6 +63,7 @@ int main(int ac, char **av) int ret, status; int lc; /* loop counter */ char *msg; /* message returned from parse_opts */ + char cmd[40]; /* * parse standard options @@ -76,6 +77,11 @@ int main(int ac, char **av) */ setup(); + /* adjust parent process so not be killed when out of memory */ + sprintf(cmd,"echo -1000 > /proc/%d/oom_score_adj", getppid()); + printf("%s\n", cmd); + system(cmd); + /* * check looping state if -i option is given */ @@ -92,6 +98,9 @@ int main(int ac, char **av) pause(); exit(0); } + /* adjust child process so it is killed first when out of memory */ + sprintf(cmd,"echo 500 > /proc/%d/oom_score_adj", pid1); + system(cmd); forks++; ret = waitpid(-1, &status, WNOHANG); if (ret < 0) -- 1.7.0.4 Best Regards, Bing-Jiun |