Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: sys/wait.h: No such file or directory [duplicate]

Tags:

c++

c

shell

windows

I'm trying to code a simple shell by C. But i can't using sys/wait.h. My code same that:

#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int main(void) {
    char command[BUFSIZ];
    int status;
    pid_t pid;

    for(;;) {
        printf("simpsh: ");
        if(fgets(command, sizeof(command), stdin) == NULL) {
        printf("\n");
        return 0;
   }

   command[strlen(command) - 1] = '\0';
   if((pid = fork()) == 0)
   execlp(command, command, 0);

   while(wait(&status) != pid)
   continue;

   printf("\n");
   }

}

I'm using dev-C++ and result is:

[Error] sys/wait.h: No such file or directory

What wrong in here? And if anyone have some suggestions for me to create a simple shell by C or C++ please give me some links or codes. thanks!

like image 450
Thangnv Avatar asked Aug 02 '13 09:08

Thangnv


1 Answers

From http://sourceforge.net/p/dev-cpp/discussion/48211/thread/e32720b4

TextTiling/util.c:8:22: sys/wait.h: No such file or directory TextTiling/util.c:26:21: sys/vfs.h: No such file or directory

These are OS specific files, but are not Windows headers. Windows does not fully support POSIX APIs. You will probably have to do some porting of the code to get it to compile and run on Windows.

You will probably have more luck building it in its intended environment (Linux or OSX perhaps, either way a UNIX-like environment). You might be able to build it under Cygwin, but that is a sledgehammer for a nut.

A simple(ish) solution is to run Linux under a Virtual Machine (using VMWare's free VMPlayer or VMServer tools for example). And then build and run teh code in a VM. The VM can access the Windows machine via a virtual network, so you can still get results and data uinto the Windows environment if you wish.

On a diferent issue, Dev-C++ will sometimes (and apparently randomly) fail when projects are in sub-folders of its installation directory (C:\Dev-Cpp).

like image 180
someone Avatar answered Oct 19 '22 19:10

someone