LinuxQuestions.org
Review your favorite Linux distribution.
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-18-2006, 10:07 PM   #1
socialjazz
LQ Newbie
 
Registered: Sep 2006
Posts: 9

Rep: Reputation: 0
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
 
Old 10-18-2006, 10:12 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
because fork() creates a copy of the originator ie parent process .....
 
Old 10-18-2006, 11:14 PM   #3
socialjazz
LQ Newbie
 
Registered: Sep 2006
Posts: 9

Original Poster
Rep: Reputation: 0
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
 
Old 10-19-2006, 12:53 PM   #4
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
Try implementing your program using clone instead of fork
 
Old 10-19-2006, 01:59 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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.
 
Old 10-19-2006, 02:42 PM   #6
ciotog
Member
 
Registered: Mar 2004
Location: Canada
Distribution: Slackware current
Posts: 728
Blog Entries: 2

Rep: Reputation: 43
Oops, shouldn't post when I'm distracted...

Last edited by ciotog; 10-19-2006 at 03:11 PM.
 
Old 10-19-2006, 04:31 PM   #7
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,455

Rep: Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172Reputation: 1172
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.
 
Old 10-19-2006, 06:48 PM   #8
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,496

Rep: Reputation: 68
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
get the PID of a separate process (no parent-child relationship) arunj Linux - Software 6 02-03-2006 02:50 AM
When I kill parent process, child isn't killed BengeBoy Linux - Software 0 08-19-2004 05:38 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 02:19 PM
about parent and child process winwar Solaris / OpenSolaris 3 07-23-2003 07:07 AM
child and parent process error jdevanand Programming 1 04-29-2002 09:13 AM


All times are GMT -5. The time now is 06:45 AM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration