Gab*_*abe 9 c++ linux recursion
int w(int x, int y){
if(x != y) {
w(x, y);
}else return x+y;
}
Run Code Online (Sandbox Code Playgroud)
这样称呼它:
w(0, 5);
Run Code Online (Sandbox Code Playgroud)
对于不同的值(如上所述),它会生成无限递归.问题是,一旦程序以这种方式启动,特定进程就会变成D模式(等待内部I/O,因此无法触及).

while(1){
if(0 != 5){
//foo
}else{
//bar
}
}
Run Code Online (Sandbox Code Playgroud)
生成R状态模式 - 完全能够获得SIGKILL.

虽然正常循环在性能方面优于递归; 系统应该仍然能够杀死进程.
为什么会这样?以及如何远程预防?
代码将由程序执行编译,该程序通过套接字将其输出返回给webclient.因此无法控制用户尝试编译的内容.
编辑:
无处不在的编译和运行代码的过程:
$ g++ main.cpp -o m
$ ./m
Run Code Online (Sandbox Code Playgroud)
EDIT2:
$ g++ --version
g++ (GCC) 4.9.2 20150204 (prerelease)
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ df --print-type
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda2 ext4 957174124 168965980 739563400 19% /
dev devtmpfs 4087124 0 4087124 0% /dev
run tmpfs 4089872 528 4089344 1% /run
tmpfs tmpfs 4089872 76 4089796 1% /dev/shm
tmpfs tmpfs 4089872 0 4089872 0% /sys/fs/cgroup
tmpfs tmpfs 4089872 1052 4088820 1% /tmp
tmpfs tmpfs 817976 12 817964 1% /run/user/1000
Run Code Online (Sandbox Code Playgroud)
测试在Arch Linux x64(使用最新的gcc)上完成.
EDIT3:
重新安装操作系统后也会出现同样的问题.该图像也已在另一台PC上使用,不会出现此问题.
我不确定是否理解了:
以这种方式启动你的命令:
./m & echo $! > mpid
Run Code Online (Sandbox Code Playgroud)
所以要杀死进程:
kill $(cat mpid)
Run Code Online (Sandbox Code Playgroud)