forks, ipc, fifos, update issues...


 
Thread Tools Search this Thread
Top Forums Programming forks, ipc, fifos, update issues...
# 1  
Old 09-28-2005
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.
# 2  
Old 09-29-2005
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.
# 3  
Old 09-29-2005
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.
# 4  
Old 09-30-2005
This might sound trite, but are you sure there is no arrray index issue?
# 5  
Old 09-30-2005
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.
# 6  
Old 09-30-2005
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?
# 7  
Old 10-02-2005
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-02-2005 at 03:15 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Issues after update

Hi guys, thanks for your kind assistance. I have a rhel6.4 server. After I did an update, the server does not reboot. Also user logins take for ever. Please any help on this matter will be appreciated . Thank you (2 Replies)
Discussion started by: cjashu
2 Replies

2. Programming

kill() function problem in client-server ipc message using 2 FIFOs

I want to have a message send & receive through 2 uni-direction FIFO Flow of data FIFO1 stdin--->parent(client) writefd--->FIFO1-->child(server) readfd FIFO2 child(server) writefd2---->FIFO2--->parent(client) readfd2--->stdout I need to have boundary structed message... (3 Replies)
Discussion started by: ouou
3 Replies

3. Solaris

errors on Netra-440: "IPC Warning: ipc: tcp_protocol: bad magic number"

I was asked to look into a problem with a Sun Netra 440 in another department. On the server in question, the relevant 'uname -a' information is, "SunOS host1 5.9 Generic_118558-16 sun4u sparc SUNW,Netra-440". That information aside, while the other admin is logged into the ALOM, these errors are... (0 Replies)
Discussion started by: Borealis
0 Replies

4. UNIX for Advanced & Expert Users

UNIX domain sockets vs FIFOs

Is there a performance advantage of one of these over the other? Obviously, it makes no sense to use normal TCP sockets or UDP sockets w/ the overhead they carry. But what about UNIX domain sockets vs FIFOs? I'd think they'd be very similar, in terms of performance and in terms of how they're... (2 Replies)
Discussion started by: mgessner
2 Replies

5. Programming

read from file using forks

i'm tring to make 2 processes each read from the same file but only one of them read the file. FILE * fileptr1; fileptr1 = fopen("file1.txt","rt"); pid2=fork(); while(1) { fscanf(fileptr1,"%s",temp1); if(feof(fileptr1)==0) { printf("%i",getpid()); //id of current process ... (6 Replies)
Discussion started by: ddx08
6 Replies

6. UNIX for Advanced & Expert Users

Question on forks and pipes

I am trying to figure out why when i have the following code int main( { printf("0\n"); fork(); printf("1\n"); exit(0);} and type in the shell a.out | cat the output of this program is 0 1 0 1 instead of 0 1 1 does anyone know? (3 Replies)
Discussion started by: Phantom12345
3 Replies

7. UNIX for Advanced & Expert Users

tar and fifos

How can I make tar read data from a fifo, instead of storing it as a fifo? (8 Replies)
Discussion started by: Corona688
8 Replies

8. Linux

A little help understanding FIFOs?

This isn't strictly a Linux question, but... I've been working on a project to archive some streaming media for time shifting using 'mplayer' and have been using FIFOs to archive in Ogg Vorbis format: mkfifo program_name.wav (mplayer -ao pcm -aofile program_name.wav &)... (0 Replies)
Discussion started by: deckard
0 Replies

9. Programming

Praying for help: FIFOs, IPC

omg i need help so bad. I've been working on a school project for what seems like an eternity and i'm close to deadline. Using FIFO's (i ahve to) to communicate between parent and child proc's. Right now I'm stuck on a read/write. fifomsg is a struct with int length and char message fields. ... (5 Replies)
Discussion started by: Funktar
5 Replies

10. UNIX for Advanced & Expert Users

forks....HELP!!! someone anyone?

Hey guys, I'm given this bit of code, but, I'm having some problems executing it with the functions I've defined so far. I'm suppose to define the funtions "parse" and "execute." Parse splits the command in buf into individual arguments. It strips whitespace, replacing those it finds with NULLS... (3 Replies)
Discussion started by: richardspence2
3 Replies
Login or Register to Ask a Question