LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Question on forking a child process (https://www.linuxquestions.org/questions/programming-9/question-on-forking-a-child-process-104553/)

brianvdc 10-16-2003 12:56 AM

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

dorian33 10-16-2003 01:35 AM

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.

Kumar 10-16-2003 04:07 AM

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.


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