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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
10-18-2006, 09:07 PM
|
#1
|
|
LQ Newbie
Registered: Sep 2006
Posts: 9
Rep:
|
child process usses same amount of ram as parent process
i use fork() to create a child process
it seems that the ram used for every damn child process seems have the same amount of ram usage as the parent process
when i type "ps" in the console, i get
59 R 1938K 0K 0.0 xxx.elf
60 S 1938K 0K 0.0 xxx.elf
61 S 1938K 0K 0.0 xxx.elf
62 S 1938K 0K 0.8 xxx.elf
63 S0 S 182K 0K 0.0 sh
80 S 1938K 0K 0.0 xxx.elf
84 S 1938K 0K 0.1 xxx.elf
can anyone tell me why is this so? and how to reduce ram usage??
Big thanks in advance
|
|
|
|
10-18-2006, 09:12 PM
|
#2
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 14,983
|
because fork() creates a copy of the originator ie parent process .....
|
|
|
|
10-18-2006, 10:14 PM
|
#3
|
|
LQ Newbie
Registered: Sep 2006
Posts: 9
Original Poster
Rep:
|
Quote:
|
Originally Posted by chrism01
because fork() creates a copy of the originator ie parent process .....
|
Any way to solve this problem?
i just want a separate thread without the copy
|
|
|
|
10-19-2006, 11:53 AM
|
#4
|
|
Member
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 727
Rep:
|
Try implementing your program using clone instead of fork
|
|
|
|
10-19-2006, 12:59 PM
|
#5
|
|
Senior Member
Registered: Jan 2003
Posts: 2,786
|
Quote:
|
Originally Posted by socialjazz
i just want a separate thread without the copy
|
Then why not use pthread? Creating threads is a pretty painless process.
If you need to stick with fork(), the glibc manual seems to suggest the common practice is to fork() and call one of the exec functions (execl(), execlp(), etc.) But I'm not 100% sure what the exec call does with the memory... I have to imagine when they say the process is replaced, they mean everything (variables, context, etc.) and not just the instruction set.
Never messed with clone(), but it looks interesting.
|
|
|
|
10-19-2006, 01:42 PM
|
#6
|
|
Member
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 727
Rep:
|
Oops, shouldn't post when I'm distracted...
Last edited by ciotog; 10-19-2006 at 02:11 PM.
|
|
|
|
10-19-2006, 03:31 PM
|
#7
|
|
Senior Member
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 4,554
|
Also don't forget that a lot of the "memory used" is shared, in that a single copy of the memory data is being used by several processes at once. Don't be alarmed at whatever Linux seems to be doing.
|
|
|
|
10-19-2006, 05:48 PM
|
#8
|
|
Senior Member
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,466
Rep:
|
Quote:
|
Don't be alarmed at whatever Linux seems to be doing.
|
LOL when i read that all i could think of was a penguin saying "YOU DIDENT SEE ANYTHING" waving his arms around
I think thats from a movie I never got around to seeing.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:02 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|