LinuxQuestions.org
Help answer threads with 0 replies.
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-18-2006, 09: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, 09:12 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,369

Rep: Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753Reputation: 2753
because fork() creates a copy of the originator ie parent process .....
 
Old 10-18-2006, 10: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, 11:53 AM   #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, 12:59 PM   #5
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
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, 01: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 02:11 PM.
 
Old 10-19-2006, 03:31 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,699
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
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, 05:48 PM   #8
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
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



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 01:50 AM
When I kill parent process, child isn't killed BengeBoy Linux - Software 0 08-19-2004 04:38 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM
about parent and child process winwar Solaris / OpenSolaris 3 07-23-2003 06:07 AM
child and parent process error jdevanand Programming 1 04-29-2002 08:13 AM

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

All times are GMT -5. The time now is 10:13 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
Open Source Consulting | Domain Registration