The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
UNIX domain sockets vs FIFOs mgessner UNIX for Advanced & Expert Users 2 03-27-2008 06:03 PM
tar and fifos Corona688 UNIX for Advanced & Expert Users 8 08-23-2006 04:21 PM
A little help understanding FIFOs? deckard Linux 0 11-01-2005 10:46 AM
Praying for help: FIFOs, IPC Funktar High Level Programming 5 05-18-2005 04:25 PM
forks....HELP!!! someone anyone? richardspence2 UNIX for Advanced & Expert Users 3 04-06-2004 12:36 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 09-28-2005
Registered User
 

Join Date: May 2005
Posts: 6
forks, ipc, fifos, update issues...

Hi, so I've got this program("main") that fork executes another ("user"). These programs communicate through fifos.

One communication is a spawn call, where user passes an executable, main forks and executes it. So, I'm keeping track of all my processes using a task table. After the fork (for the spawn call), the new child adds itself to the task table and then waits for the "user" to finish before executing. So, the user finishes what it needs, calls the end method on "main", which checks to see if there's a waiting process. It turns out when I show() my task table, the new child that I added isn't there! I can't figure out why at all. Any ideas?

Here's the 2nd child when it gets created.

Code:
pid = Fork(); 
if(pid == 0) { 
      //blah blah 
      tbl -> set(spawn_tid_c, spawn_pid_c); 
      tbl -> show(); 
      //wait 
}
Here's the output.

+ main + forking
+ TaskTbl + set(01, 19976) method called
+ TaskTbl + (01, 19976) added
<TaskTbl> has 2 items
0: <00,19975>
1: <01,19976>
+ main + waiting for system call message
+ user1 + calling s_end()
+ main + syscall task end received
<TaskTbl> has 1 items
0: <00,19975>

the end function is called immediately after the spawn function finishes, and I've checked everywhere to find something that would remove the task but the only way to do so would be for me to intentionally remove it ( remove -> (task, proc)), which I'm not doing.

I have no idea why the table is only showing 1 item immediately after. Help would be greatly appreciated.
Reply With Quote
Forum Sponsor
  #2  
Old 09-29-2005
linuxpenguin's Avatar
Registered User
 

Join Date: May 2002
Location: India
Posts: 295
Hi,
I am not getting a clear idea of what is happening.
Do you mean to say that the child part of fork is never executed?
or is it executed only once. Is show() by any chance using an exec function.

Please clarify the problem.
__________________
War doesnt determine who is right, it determines who is left
Reply With Quote
  #3  
Old 09-29-2005
Registered User
 

Join Date: May 2005
Posts: 6
so program starts, main forks and executes child1, there's some communication, child1 sends a spawn message to main, but the new child needs to wait until the first child finishes. So, main forks, new child adds itself to the task table and begins to wait until child1 is finished. Main proceeds with child1 until it's done. Immediately after child1 is done, the new child executes child2, etc. I need to tell my main that there is a child waiting, and the order of execution so I use a task table. problem is after child1 is done, while new child (not yet executed child2) is waiting, main checks tasktable to see if there's another entry, which for some reason there isn't, but there should be.

and no, show is a call to TaskTable class which just displays entries. Any more questions just ask. Thanks for help.
Reply With Quote
  #4  
Old 09-29-2005
Registered User
 

Join Date: Sep 2005
Posts: 6
This might sound trite, but are you sure there is no arrray index issue?
Reply With Quote
  #5  
Old 09-29-2005
Registered User
 

Join Date: May 2005
Posts: 6
the only array index is inside tasktable, which i've tested on a nonforking program multiple adds and removes, etc. and it all works fine. updating it with 2 processes apparenlty doesn't share.
Reply With Quote
  #6  
Old 09-30-2005
Registered User
 

Join Date: Sep 2005
Posts: 6
Tell me something, after the first child proc has finished executing, it should *not* show up in the task table right? and you should see the second one? or is the task table supposed to have all entries at all times?
Reply With Quote
  #7  
Old 10-01-2005
Registered User
 

Join Date: Aug 2005
Location: Saskatchewan
Posts: 979
Is this table in explicitly shared memory? If not, each process gets it's own copy along with it's own independent memory space. Changes in one won't change any of the others. This is very different from threading, where everything lives in the same memory space.

Last edited by Corona688; 10-01-2005 at 11:15 PM.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 02:40 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0