• 0

Problem with wait() system call


Question

I'm writing a very simple program in linux to fork a child process. The only problem is that when I have the parent process call wait(&status), i get an error that says " 'status' declared as reference but not initialized" status is defined as int status; right in main so i'm not sure what the hell I am doing wrong, although I'm sure it's something simple. Can anyone offer some suggestions?

Link to comment
https://www.neowin.net/forum/topic/143493-problem-with-wait-system-call/
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Thanks for the offer, but i'd rather not give out the code since it's a hw assignment, university's can be extremely anal when it comes to this sort of thing. I tried changing the variable name and i got the same error. I'm using the g++ compiler. I guess i'll just try to compile it on unix to see if i get the same error. I named the .out file fork, maybe that's causing a problem? In any case i'll try it tomorrow and let you know what happens. Thanks for the input.

  • 0

Hmm, i just tried the code you posted, this is what I got:

nclude <iostream>

using namespace std;

#include <sys/types.h>

#include <unistd.h>

int main(void)

{

int status;

if (fork() == 0)

{

return -1;

}

wait(&status);

return 0;

}

errors:

fork2.cpp: In function `int main()':

fork2.cpp:14: conflicting types for `wait&status'

fork2.cpp:9: previous declaration as `int status'

fork2.cpp:14: `status' declared as reference but not initialized

  • 0
  PseudoRandomDragon said:
I couldn't compile the code for you, didn't have all the libraries. Curse you Borland C++...

fork is not supported in windows.

In Windows, you would use CreateProcess to get an equivalent functionality (not completely)

Cygwin is the only library I know of which has fork() implemented for Windows.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • They always have. This just updates what's included out of the box during the initial install.
    • So basically their prebuilding it into the ISOs?
    • Microsoft shares Defender anti-virus update for new Windows 11/10 ISOs by Sayan Sen Following the one for Lumma last month, Microsoft has also published a new Defender update for Windows 11/10/Server installation images this month. This update package is necessary as a Windows installation image may contain old, outdated anti-malware definitions and software binaries. Aside from better security, these updates can also provide improved performance benefits in some cases. When a new Windows installation is set up, there may be a temporary security risk due to outdated Microsoft Defender protection in the OS installation images. This happens because the antimalware software included in these images might not be up to date. Thus Microsoft says that these updated definitions essentially help close this protection gap. Microsoft delivered the latest security definitions for Windows images via security intelligence update version 1.431.54.0. The Defender package version is also the same. It applies to Windows 11, Windows 10 (Enterprise, Pro, and Home editions), Windows Server 2022, Windows Server 2019, and Windows Server 2016. Microsoft writes: From Microsoft's security bulletin, we learn that the security intelligence update version 1.431.54.0 was released this past week adds threat detections for various backdoor exploits, trojans, among others. For those wondering, the latest intelligence update is version 1.431.155.0 at the time of writing.
    • “In other news about OneDrive frustration, Microsoft recently locked out a user who was attempting to move a bunch of important data from old hard drives to OneDrive.” - It was probably CSMA..
    • Just what I needed! An extremely expensive pair of sunglasses that I will lose and cannot use indoors. My life will be complete. I trust Meta AI watching my entire life happen. It's going to be the best ever!
  • Recent Achievements

    • One Month Later
      SekTheFirst earned a badge
      One Month Later
    • First Post
      zayanhani earned a badge
      First Post
    • First Post
      HarryTaylor earned a badge
      First Post
    • One Year In
      Eternal Tech earned a badge
      One Year In
    • One Month Later
      Eternal Tech earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      651
    2. 2
      ATLien_0
      233
    3. 3
      Michael Scrip
      226
    4. 4
      Steven P.
      140
    5. 5
      +FloatingFatMan
      139
  • Tell a friend

    Love Neowin? Tell a friend!