2014-06-08 10:13:29 +04:00
|
|
|
/* This file is part of ToaruOS and is released under the terms
|
|
|
|
* of the NCSA / University of Illinois License - see LICENSE.md
|
|
|
|
* Copyright (C) 2013-2014 Kevin Lange
|
|
|
|
*/
|
2012-07-07 08:08:28 +04:00
|
|
|
/*
|
|
|
|
* thrash-process
|
|
|
|
* Creates a lot of processes.
|
|
|
|
*/
|
2011-12-16 03:21:28 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <syscall.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2014-04-27 12:37:33 +04:00
|
|
|
#include <sys/wait.h>
|
2011-12-16 03:21:28 +04:00
|
|
|
|
|
|
|
int main(int argc, char ** argv) {
|
2011-12-27 05:23:58 +04:00
|
|
|
int quiet = 0;
|
|
|
|
if (argc > 1) {
|
|
|
|
if (!strcmp(argv[1],"-q")) {
|
|
|
|
printf("I'll be quiet...\n");
|
|
|
|
quiet = 1;
|
|
|
|
}
|
|
|
|
}
|
2011-12-16 03:21:28 +04:00
|
|
|
for (int j = 0; j < 1024; ++j) {
|
|
|
|
volatile int k = fork();
|
2011-12-27 05:23:58 +04:00
|
|
|
if (!quiet)
|
|
|
|
printf("I am %d, I got %d\n", getpid(), k);
|
2011-12-16 03:21:28 +04:00
|
|
|
if (k == 0) {
|
2011-12-27 05:23:58 +04:00
|
|
|
if (!quiet || !(j % 10))
|
|
|
|
printf("I am %d\n", getpid());
|
2011-12-16 03:21:28 +04:00
|
|
|
return 0;
|
|
|
|
} else {
|
2011-12-27 05:23:58 +04:00
|
|
|
if (!quiet)
|
|
|
|
printf("Waiting on %d\n", k);
|
2014-04-27 12:37:33 +04:00
|
|
|
waitpid(k, NULL, 0);
|
2011-12-16 03:21:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|