Google Interview Question
Software Engineer in TestsGood old forkbomb :) I accidentally crashed my school servers the night before a big assignment was due :)instant hero status :) and yes, it was pretty instant...
Randomly kill de system processes...whatever u do with a program like c wont crash de system cos a good os wont allow it
using malloc and calloc function without freeing the memory will fill all the RAM.... but to crash entire system create a txt file in OS DIR by using 'C'. now jump the file poiter and write garbage things at random location.... somewhere it will be corrupting sys files.... and thats all... sys crashed...!
AFAIK that will only cause an infinite loop - it will freeze the program but won't crash the system. a forkbomb can be implemented like this..it has a similar concept to what you did except instead of calling itself again and again, it will make a new process and both will call it, then 4 processes, etc...2^n processes will be made:
#include <unistd.h>
int main(void)
{
for(;;)
fork(); /* each time this is called, # processes *=2 */
return 0;
}
Forkbombs are *not* the answer - it is quite easy to limit the number of processes that a given user may have running at a given time. The only way to crash a system "immediately" is to remove the power source or to cause some serious trauma to the hardware (see: securing your windows box using nothing but a hammer)
The best ways to crash a system:
1. Memory overload. Create an RT process with a high consuming ever increasing memory. Crashes Linux, if the RT process is running as root
2. Over write the swap partition, and do a memory overload. Corruption occurs.
3. In Linux, write a kernel program, that can cause kernel panic when called. (Similar to ever popular blue screen of Windows)
Somehow all these things will work in Linux or Windows. I believe Solaris and AIX have internal defense for such issues, with stuff like pre-emptive kernels
Anuj,
Your answers all seem to assume you have root access. If you do have root access, surely a forkbomb is the easiest way to go (you can even override the number of proccess per user limitation if there is one). I think the challenge of the question is to freeze a per user memory and proccess limited system under a normal user.
if there's a way to crash the system without sudo - meaning cause kernel panic, then its a security issue. so there can't be a way to do it without sudo.
if i have sudo, i'll download the kernel source code, add a seg fault inside the kernel, compile it, and replace the kernel executable in the filesystem.
sudo reboot and you'll get kernel panic.
This question did not state you had to write a program or do anything at the command prompt so a six year old kid could give a better answer than what has been given so far.
How about something as novel as disconnecting the power cord from the computer???
I bet that will crash any computer no matter which operating system you are using :-)
Actually, a six year old kid would probably not come up with that kind of an answer.
A kid answer would likely be smearing peanut butter on the mother board and then pour milk on the central CPU.
In this day and age, you think removing the power cord will crash the system? There are these devices called laptops which have batteries in them now so that plan may not work. Also UPS supplies....so other tricks like milk might work, but why waste milk when water can do the same or just use your body weight to crush the pieces.
Just write a simple code
while(malloc(sizeof(char)));
It will keeps on allocating the memory until memory finishes and then system will crash as there no memory for any other process...
What a fucking moron...i can't believe guys like you manage to get jobs in good companies..
dude come on. look out the other answers and see how stupid they are too. get over with it.
I like his answer.... clearly he was just knocking windows, which is junk I have to use, compared to the reliability of mac, linux, or unix for that matter.... Until recent years windows would crash without regularly... at least it consistently sucked
a forkbomb might do it
- woohoo February 27, 2011