LinuxQuestions.org
Visit Jeremy's Blog.
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-16-2003, 01:56 AM   #1
brianvdc
LQ Newbie
 
Registered: Feb 2003
Location: Hillsboro, OR
Posts: 13

Rep: Reputation: 0
Question on forking a child process


I have some general questions about creating child processes in an application on Redhat Linux. We have a daemon listening on a certain port (623). Everytime the user connects to it, we fork a child process to go out and do the work.

Our documentation states that the daemon will allow up to 500 connections at a time which means their could be a total of 501 processes at the same time. Is this a problem with Linux? I see that Linux has a limit of 256 threads per process, but I can't find a limitation of the # of processes. I also don't know if this is considered a poor programming practice.

What happens to the parent process if the child process has a segmentation fault. Will the parent process die as well?

Linux documentation states that it frees all memory once a process exits. Is this true for a child process as well if the parent is still running. In the past, when we used threads instead of processes, I saw the memory usage was increasing over time. While I would like to find these memory leaks, it would be comforting to know that Linux is freeing the memory.

Thanks for all responses.

Brian
 
Old 10-16-2003, 02:35 AM   #2
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
There is no practical limitations. The child and parent are completely independent besides the matter that the parent is responsible for cleaning after the finished child process. So you should use wait() or waitpid() function. If you used threads you should know that the thread need to be joined to the threads (unless it is detached). Same concerns child process. It needs to be cleaned. Usually the best way is to do it as SIGCHLD signal service. I don't remember but I think that when one of child dies this signal is also send to the parent. Another matter is when parent dies. This time you get a lot of zombies.
 
Old 10-16-2003, 05:07 AM   #3
Kumar
Member
 
Registered: Sep 2003
Location: Pune, India
Distribution: Red Hat
Posts: 106

Rep: Reputation: 15
I think it's not a nice practice to create so many processes when you can use thread instead. If you are talking about threads then segmentation fault in that thread will cause the whole process to terminate. But if you are talking about processes, then only that process will terminate since they are independent entities. Also, there are no limitations on the maximum number of threads you can create. refer to /proc/sys/kernel/threads-max. Only problem can be available memory. Also don't forget to use pthread_join to avoid memory leaks as resources allocated to threads are not deallocated until pthread_join is called on it.
 
  


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
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 08:26 AM
How to kill a Child and all its subsequent child process in C shayer009 Programming 3 12-04-2007 01:40 AM
Newbie on forking child process and I/O redirection neo_in_matrix Programming 4 09-16-2005 04:05 AM
forking 7 child processes ianomc Programming 5 11-07-2004 01:33 PM
Killing a child process from another child marri Programming 6 10-01-2004 08:08 PM

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

All times are GMT -5. The time now is 03:25 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