Integer Overflow with PID in C

Asked

Viewed 49 times

0

Hello. I’m trying to implement a C (for 3DS) program that manages processes and finishes them until I can generate an Integer Overflow in the PID to be 0, but I don’t know exactly how to do it. What would be the easiest way?

1 answer

0

An idea would be to create a loop by making Fork(). Something like:

#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
...
int p;
for (p = 0; p < INT_MAX; p++) {
  int status;
  if (!fork()) { // processo filho
    sleep(1); // dormir um tempinho para que o pid nao seja reaproveitado
    exit(0);
  }
  wait(&status, WNOHANG);
}

I haven’t tested the code, but I think you’ll need Wait(), otherwise you’ll end up with a trillion zombie processes. You may also need to reduce Sleep() time by replacing it with a usleep(), so you don’t have more concurrent processes than your machine supports.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.