/*1* Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 20092* The President and Fellows of Harvard College.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. Neither the name of the University nor the names of its contributors13* may be used to endorse or promote products derived from this software14* without specific prior written permission.15*16* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829/*30* forkbomb - apply malthus to an operating system ;-)31*32* DO NOT RUN THIS ON A REAL SYSTEM - IT WILL GRIND TO A HALT AND33* PEOPLE WILL COME AFTER YOU WIELDING BASEBALL BATS OR THE AD34* BOARD(*). WE WARNED YOU.35*36* We don't expect your system to withstand this without grinding to37* a halt, but once your basic system calls are complete it shouldn't38* crash. Likewise for after your virtual memory system is complete.39*40* (...at least in an ideal world. However, it can be difficult to41* handle all the loose ends involved. Heroic measures are not42* expected. If in doubt, talk to the course staff.)43*44*45* (*) The Administrative Board of Harvard College handles formal46* disciplinary action.47*/4849#include <unistd.h>50#include <err.h>5152static volatile int pid;5354int55main()56{57int i;5859while (1) {60fork();6162pid = getpid();6364/* Make sure each fork has its own address space. */65for (i=0; i<300; i++) {66volatile int seenpid;67seenpid = pid;68if (seenpid != getpid()) {69errx(1, "pid mismatch (%d, should be %d) "70"- your vm is broken!",71seenpid, getpid());72}73}74}75}767778