Re: weird fork problem
- From: Darko <darko.maksimovic@xxxxxxxxx>
- Date: Wed, 31 Oct 2007 17:48:29 -0000
On Oct 31, 8:01 am, bel...@xxxxxxxxx wrote:
Finally it resulted to be a memory leak ... but it was funny because
neither the "free" command or "top" did not report excesive memory
usage.
Searching in ulimit, the only limitation that I may be breaking is the
stack size, which is limited to 8192 kB.
On 29 oct, 08:16, Amol Vaikar <amol.vai...@xxxxxxxxx> wrote:
On Oct 29, 2:22 am, bel...@xxxxxxxxx wrote:
Hi all,
I am having a strange issue with a fork call. After some runs, I
cannot call fork from my program. This is my code:
pid_t pID=-1;
while (pID<0)
{
cout << "trying to fork ... " << endl;
pID = fork ();
if (pID < 0) // failed to fork
{
cerr << "errno: " << strerror(errno) << endl;
cerr << "Failed to fork" << endl;
sleep(5);
}
}
After a number of runs that varies between 20 and 30, I have the
following error output:
trying to fork ...
errno: Cannot allocate memory
Failed to fork
trying to fork ...
errno: Cannot allocate memory
Failed to fork
And so on. But a look to free gives enough memory:
$ free -m
total used free shared
buffers cached
Mem: 1011 656 355 0 30
353
-/+ buffers/cache: 271 739
Swap: 1176 0 1176
I have about 355 MB of physical and more than 1GB of swap, which
should be enough.
I also had a look to the number of processes running:
$ ps aux | wc -l
111
And the system limitations:
$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
max nice (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 8183
max locked memory (kbytes, -l) 32
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
max rt priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 8183
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
So I have no idea where the problem is ... any help please?
Thanks
I understand that you are running your program as a non-root user?
If that assumption is right, then does the number of child processes
that the parent process can spawn change if you are logged in as root
(or if the parent process is running on behalf of root)?
If the answer to that is yes, then as is mentioned in other comments
to this messae, you are probably reaching some resource limit while
running the parent process as non-root.
Try changing open files limit etc.
HTH.
A memory leak where? Concerning the fork() function or elsewhere in
your program?
It is a sad fact that malloc will almost never return NULL as a sign
there's no memory left,
nor will C++'s new operator, but instead they usually just block the
whole system, slow
it down or kill the process. Or is it just from my experience?
.
- References:
- weird fork problem
- From: belion
- Re: weird fork problem
- From: Amol Vaikar
- Re: weird fork problem
- From: belion
- weird fork problem
- Prev by Date: Re: To Change PS1 automatically
- Next by Date: Re: Why localize structures in this case.
- Previous by thread: Re: weird fork problem
- Next by thread: Re: weird fork problem
- Index(es):
Relevant Pages
|