Results 1 to 2 of 2
Hi,
Say I have a C program that does:
While(1){system(“ls”);}
The system() call creates a new PID at each call. Therefore, when the maximum number of PIDs is reached, the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 02-27-2013 #1Just Joined!
- Join Date
- Mar 2011
- Posts
- 8
How to limit or reset PIDs
Hi,
Say I have a C program that does:
While(1){system(“ls”);}
The system() call creates a new PID at each call. Therefore, when the maximum number of PIDs is reached, the ls command becomes <defunct> and eventually the system crashes.
I tried also popen() but it is the same result.
Is there a way of avoiding this behavior?
Thanks,
S
- 03-01-2013 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 10,233
This is when you need to wait on death-of-child events with wait() or waitpid(), inside your loop. That will remove the defunct pid from the process tree, otherwise the observed behavior is expected. The system() command does a fork/exec and each fork generates a new pid, as does popen(). Alternatively, you can use one of the exec...() functions, but then your root process will no longer exist. IE, using exec() without a fork will transform your current process into a new one, but using the same PID.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
