可以让你的Linux死掉的程序
作为Linux的用户,如何故意让自己的Linux死机?
这个问题看似简单,但是真要去做,还不是那么容易能做到的。
不信读者先不要看后文,先自己尝试一下如何让自己的Linux死机。
目前我已探索出了3种方法,罗列如下:
方法一、无限fork循环
用这种方法可以耗尽系统资源,首先是感觉系统变慢,然后感觉系统死机。
这种方法效果不是最好的,受害者可以在终端运行top命令看到问题出在什么地方。
程序如下:
#include <sched.h>#include <stdio.h>#include <stdlib.h>int main() { struct sched_param sched; sched.sched_priority = 99; if ( 0 != sched_setscheduler(0, SCHED_FIFO, &sched) ) { printf("error\n"); exit(1); } while(1) { // endless loop; }}