LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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 05-10-2005, 08:19 AM   #1
biiiep
Member
 
Registered: Aug 2003
Posts: 39

Rep: Reputation: 15
fork and multiple son processes


hallo,

i want to create a program with multiple son processes. the problem i have is that the son processes have different tasks. and i want to be sure to start every son process with his task only one time.

how can i assure this? is it possible to do this with the fork function??
 
Old 05-10-2005, 10:57 AM   #2
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Why not use pthreads instead of fork? Pthreads spawns processes where each process can be a completely different task from any other one. You basically code a function that is to become your spawned process, call the pthread process creation function giving the name of the function you want the process to execute and away it goes.
 
Old 05-11-2005, 05:38 AM   #3
biiiep
Member
 
Registered: Aug 2003
Posts: 39

Original Poster
Rep: Reputation: 15
but i thought scheduling within kernel 2.4 is different between processes and threads, so the threads get less calculating time from the processor.

ans i prefer controlling this directly

but thanks for the idea
 
Old 05-11-2005, 10:48 AM   #4
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
I believe (but don't quote me ) that both threads and processes use the same Linux kernel scheduler. Without actually looking at the pthreads source, and from just watching running applications, it looks like a pthreads thread is assigned a unique process ID and is subjected to the same kernel interactions as other processes. Only with pthreads you have other functions that make it much easier to control the type of scheduling and thread priority that is used on each of the individual threads.

How do you propose to control the time slicing using processes?

If I remember my internals correctly, using fork() just copies code space to the new process - data space is shared with the parent. So you could use a global and set it before calling fork(). Once the parent spawns the new process, the child can look at the global to see what functionality it should really be executing. Of course, you should also use some kind of signaling mechanism (another global that the child sets and the parent looks at) to make sure that it is safe for the parent process to change the global and spawn the next child after the currently spawned child understands what functionality it should be running. This will prevent the parent from spawning children too quickly, and cause duplicate children activities.

I have used both techniques over the years. (Using the fork() method because pthreads did not exist) However I also come from a realtime embedded background using numerous realtime OSes and using pthreads gives me a much more deterministic program (IMHO) than using fork().
 
Old 05-11-2005, 11:00 AM   #5
biiiep
Member
 
Registered: Aug 2003
Posts: 39

Original Poster
Rep: Reputation: 15
thanks for the response... this was the answer i needed
 
  


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
Multiple threads vs Multiple processes deveraux83 Programming 1 05-11-2005 10:22 AM
why there're lots of child processes when fork? iclinux Programming 3 01-18-2005 07:09 AM
Multiple Processes Appearing! Riddick Suse/Novell 0 12-06-2004 05:27 PM
multiple mysqld processes lsimon4180 Linux - Software 2 10-03-2004 03:42 PM
multiple instances of processes? ararag Linux - Software 2 07-31-2004 10:27 AM


All times are GMT -5. The time now is 02:48 AM.

Main Menu
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