Hello. I'm trying to implement a C program (for 3DS) that generates processes and finishes them until I can generate an Integer Overflow in the PID so that it is 0, but I'm not exactly sure how to do this. What would be the easiest way?
Hello. I'm trying to implement a C program (for 3DS) that generates processes and finishes them until I can generate an Integer Overflow in the PID so that it is 0, but I'm not exactly sure how to do this. What would be the easiest way?
One idea would be to create a loop by forking (). 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 did not test the code, but I think you'll need wait (), otherwise you'll end up with a trillion zombie processes. Maybe you also need to reduce sleep () time, replacing it with a usleep (), to have no more concurrent processes than your machine supports.