child exits with error 218

need some help with my code , im supposed to fork a child and wait for it co complete processing the fib , which it then has to output to shared memory where the parent will print out to screen.
all im gettin thus far is error 218 when im waiting for the child to complete. where am i going wrong , my code below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96

#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#define MAX_SEQUENCE 10

typedef struct {
	long fib_sequence [MAX_SEQUENCE];
	int sequence_size;
} shared_data;

using namespace std;

long fib( unsigned long n )
{
	if( n <= 1 )
	{		
		return 1;
	}
	else 
	{
		return fib(n-1)+fib(n-2);
	}
}

void printFib( shared_data * me , unsigned long t )
{
		int ct = 0;
	
		me->fib_sequence[ct] = 0;
	
		for( unsigned long i = 0; i <= t ; i++ )
		{
		ct++;
		me->fib_sequence[ct] = fib( i );
		}

}

int main(int argc, char** argv)
{
	pid_t pID,wpi;
	int status,seg_id;
	shared_data * shared_mem;
	
	int vic = atol(argv[1]);
	
	if( (vic < 0) || (vic > MAX_SEQUENCE) )
	{
		cout<<"Number Error" <<endl;
		exit(1);
	}
	
	seg_id = shmget(IPC_PRIVATE,sizeof(shared_data), 0644 | IPC_CREAT );
	
	shared_mem = ( shared_data * ) shmat( seg_id , NULL , 0 );
	
	shared_mem->sequence_size = vic;
	
	pID = fork();

	if( pID == 0 )
	{
		printFib( shared_mem , vic);
	}
	else
	{
	  wpi = waitpid( pID,&status,WNOHANG);
	  
      if( !WIFEXITED(status) )
      {
         cerr << "waitpid() exited with an error: Status= " 
              << WEXITSTATUS(status) << endl;
      }
      else if( WIFSIGNALED(status) )
      {
         cerr << "waitpid() exited due to a signal: " 
              << WTERMSIG(status)    << endl;
      }
      else
      {
		  cout << shared_mem->fib_sequence <<endl;
		  shmdt(shared_mem);
		  shmctl(seg_id,IPC_RMID,NULL);
	  }		
	}
	
	return 0;
}
changed the wait to wait(NULL). code works ok now.
The child process not finished when the calling thread is running.you must be waitting the child process finished,so
you should changed the code:
wpi = waitpid( pID,&status,WUNTRACED);
man waitpid subroutine hints:
The WNOHANG option prevents the
calling thread from being suspended even if there are child processes to wait for. In this
case, a value of 0 is returned indicating there are no child processes that have stopped or
terminated. If the WUNTRACED option is set, the call should also return information when
children of the current process are stopped because they received a SIGTTIN, SIGTTOU,
SIGSSTP, or SIGTSTOP signal.

good luck

Welcome to <a href="http://www.nicelouboutin.com"> Christian Louboutin Shoes </a>, UK on-line store! Now an

extensive selection of super-fashion Christian Louboutin Shoes with different colors and styles are

provided at the most competitive prices. You can buy <a href="http://www.nicelouboutin.com"> Christian

Louboutin Pumps </a>,Christian Louboutin Boots,Christian Louboutin sandals at our online store. Our goal is

to make all of you enjoy the top fashion and become the most charming women with our beautiful shoes.except

that,Here are new arrivals of all kinds of Yves Saint Laurent and Jimmy Choo Shoes.will you have a good

time in our YSL and <a href="http://www.nicelouboutin.com"> Jimmy Choo Shoes </a> On Sale.
Topic archived. No new replies allowed.