hello
i'm writing a program in c++ and i'm using linux.
i use fork() in order to create a process and then i want to wait for the child process
to finish so its something like that:

pid=fork();
      if(pid<0)
      {
	cerr << "Failed to fork" << endl;
	exit(1);
       }
	if(pid==0){
	 /*do what you have to do*/		
	 exit(0);
	}
	int status;
	wait(&status);

the thing is that it doesnt accept this syntax of wait()
which is really strange as in C works fine.
can anybody tell me whats wrong?

Could you post the exact error message you are getting, please?

it tells me that "status" was previously declared although i havent declared it anywhere. maybe its something wrong with the libraries included.these are the libraries i include below:
#include<stdio.h>
#include <iostream>
#include<string.h>
#include <poll.h>
#include <signal.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/types.h>
#include <fstream>
#include <sys/times.h>
#include <unistd.h>

I would venture to guess that one of those libraries has declared 'status as a variable or function. Try changing the name to something like 'mystatus' or 'waitstatus' and see if you still get an error.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.