toaruos/userspace/util/thrash-process.c
Kevin Lange 4d8335ad75 Implement proper wait/waitpid.
This is a pretty big commit, so let's run through it in parts:

- All of the userspace changes are to switch away from syscall_wait
  Mostly, this is to waitpid; some things were tweaked to do things
  "properly" instead of waiting for particular processes. Init has
  been fixed to do a proper spin wait.
- syscall_wait is gone - as are its uses. newlib bindings have been
  using just waitpid for a while now.
- waitpid now performs like a Unix waitpid
- process reaping is no longer a "do this on next change thing":
  it happens when a process is waited on, like it should
  (That means we can have real zombies: terminated processes that
  have not yet been waited on)
- Reparenting of children to init has been implemented, so you
  can fork-daemonize!

Overall, this is pretty big... So I hope it doesn't break everything.
2014-04-27 01:37:33 -07:00

37 lines
670 B
C

/*
* thrash-process
* Creates a lot of processes.
*/
#include <stdio.h>
#include <stdint.h>
#include <syscall.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
int main(int argc, char ** argv) {
int quiet = 0;
if (argc > 1) {
if (!strcmp(argv[1],"-q")) {
printf("I'll be quiet...\n");
quiet = 1;
}
}
for (int j = 0; j < 1024; ++j) {
volatile int k = fork();
if (!quiet)
printf("I am %d, I got %d\n", getpid(), k);
if (k == 0) {
if (!quiet || !(j % 10))
printf("I am %d\n", getpid());
return 0;
} else {
if (!quiet)
printf("Waiting on %d\n", k);
waitpid(k, NULL, 0);
}
}
return 0;
}