Return to BSD News archive
Path: sserve!manuel!munnari.oz.au!uunet!dtix!darwin.sura.net!mips!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!hobbes.physics.uiowa.edu!news.uiowa.edu!icaen.uiowa.edu!gdcarson From: gdcarson@icaen.uiowa.edu (Gregory Donald Carson) Newsgroups: comp.unix.bsd Subject: Fork/Pipe Help Message-ID: <1992Jul14.233856.29659@news.uiowa.edu> Date: 14 Jul 92 23:38:56 GMT Sender: news@news.uiowa.edu (News) Organization: Iowa Computer Aided Engineering Network, University of Iowa Lines: 45 Nntp-Posting-Host: l_cae09.icaen.uiowa.edu Hello; I have a pipe question/problem. I have one program that generates data in an array that I need to pass to another program through a pipe. The program that needs to receive the array data needs to get the x and y position in the array and the array value at that position from the first program after it has been forked off the first. So the problem/question is, how do I first set up a pipe between two programs like this, and then fork the second off and have it continue to get the information generated by the first program. I think it should look something like this...please mail examples if you can...HELP (the system is UNIX, the language C) first_prog() { declarations, etc... short int array[128][128]; int position_x, position_y, x,y; /* put some initial data into the array to be sent to second_prog upon forking */ /* set up the pipe here? */ /* fork the other prog */ fork(); execl( second_prog(), position_x, position_y, array); for(x=0;x<128;x++) for(y=0;y<128;y++) { array[x][y] = x; position_x = x; position_y = y; /*send position_x, position_y, and array[x][y] data to second_prog*/ } etc... } second_prog(o_array,x_pos,y_pos) short int o_array[ ][ 128 ]; int x_pos, y_pos; { declarations etc... /* do something with initial data from frist_prog and get ready to receive data from pipe */ /* get position_x, position_y, array[x][y] from first_prog */ printf( "%d, %d position of array is %d.\n", x_pos,y_pos,o_array[x][y]);