Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A C program to crash the system

Tags:

c

A few days back I had an interview, and I was asked to write a program in C which crashes the system/which shuts down the system. Needless to say I felt pretty dumb having no clue on how to even approach :(

Still I gave it a try, writing programs which use a lot of memory. But my interviewer was not satisfied with any of my techniques.

like image 617
false9striker Avatar asked Oct 03 '11 05:10

false9striker


2 Answers

It's easy to write a program that invokes undefined or implementation-defined behavior. Some of those programs could potentially crash the system.

But by definition, this is inconsistent. And modern OSes take pains (though not 100% successfully) to prevent a rogue app from crashing the system.

like image 53
Matthew Flaschen Avatar answered Oct 10 '22 02:10

Matthew Flaschen


There is no portable way to write a C program that crashes the system.

A fork bomb might or might not bog down a system. Of course fork is not portable -- and a system can defend itself against such attacks by limiting the number of processes a given account can create.

Of course there's always this:

#include <stdio.h>
int main(void) {
    puts("HEY YOU, PULL THE PLUG!!");
    return 0;
}
like image 27
Keith Thompson Avatar answered Oct 10 '22 03:10

Keith Thompson