LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-22-2003, 01:04 AM   #1
brianvdc
LQ Newbie
 
Registered: Feb 2003
Location: Hillsboro, OR
Posts: 13

Rep: Reputation: 0
Memory usage when spawning child processes


I have an app that forks a child process on every connection. The child process will last a few seconds to a minute and then complete. I am using the wait API to clear up the resources. When I issue a ps -eH | grep *** it does not show the completed child processes so I am confident that they are closing successfully.

Anyways, after heavy usage (20,000 connections) my memory goes up to 90% and the OS starts using swap memory. This is according to the gnome system monitor. I also monitor the parent process which is the only process that always stays in memory. The memory for this process never increases.

I was told that once the child process completes all memory is freed up. So with this theory, the only way my used memory could steadily climb is if the parent process is leaking memory which as I stated above is not happening.

I am concerned that after a few days, I will use up all my swap memory and my application will crash. Are the child processes trully freeing up memory or is this just related to Linux caching stuff until it needs this memory.

Thanks for all responses.
 
Old 10-22-2003, 05:37 AM   #2
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
Hi,
Since you are using wait(), all the resources should be freed automatically. But have you made sure that your child processes are not leaking any memory??? I guess your memory usage will go up if the child process is leaking memory. One more thing that I would like to add is why don't you go for threading? What you are doing is theoretically correct but see if you can implement the same with threads.
 
Old 10-22-2003, 11:27 AM   #3
brianvdc
LQ Newbie
 
Registered: Feb 2003
Location: Hillsboro, OR
Posts: 13

Original Poster
Rep: Reputation: 0
If a child process leaks memory, will that memory be freed up when the child exits?
 
Old 10-23-2003, 12:25 AM   #4
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
No, you need to free memory your self. Like if you have used malloc() inside child process, then don't forget to use free() before teminating the program.
 
Old 10-24-2003, 06:03 AM   #5
dimm_coder
LQ Newbie
 
Registered: Oct 2003
Location: Minsk, Belarus
Distribution: Mandrake, FreeBSD
Posts: 28

Rep: Reputation: 15
Quote:
Originally posted by Kumar
No, you need to free memory your self. Like if you have used malloc() inside child process, then don't forget to use free() before teminating the program.
No, when process exits, all its memory will be freed up. U can have some memory leaks (kernel memory) if U donot handle its exit rightly ( I mean U need to call wait() for its pid or process SIGCLD signal from your parent process ), otherwise a record for the exited process keeps in the system process table (and this child process becomes a zombie).

Last edited by dimm_coder; 10-24-2003 at 06:06 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
forking 7 child processes ianomc Programming 5 11-07-2004 12:33 PM
how to determine cpu usage, memory usage, I/O usage by a particular user logged on li rags2k Programming 4 08-21-2004 04:45 AM
Listing processes by memory usage? Seventh Linux - Newbie 3 06-17-2004 10:05 AM
Rotatelogs - Do I have too many child processes? fireman949 Linux - Software 2 06-08-2004 02:04 PM
parent and child processes skora Programming 5 11-02-2003 10:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration