Onaylı Üye
Kod:
C:
#include <sys/wait.h>
#include <sys/wait.h>
Tam bundan kaynaklanıyor. Sistem Windows.Bu hata c programında "sys/wait.h" başlık dosyasını kullanmaya çalıştığında derleyicinin bu dosyayı bulamamasından dolayı kaynaklanıyor olabilir
I switched to Ubuntu then it's fixed.The header file "sys/wait.h" is typically used in Unix-like systems, such as Linux or macOS, for handling child processes in C or C++ programs. However, it may not be available in some systems or compilers, especially on Windows.
If you are encountering an error related to "sys/wait.h" in your C or C++ program on Windows using Code::Blocks, it is likely because the header file is not available in the Windows environment. In that case, you may need to find an alternative solution or approach to achieve the desired functionality.
One alternative solution could be to use a platform-independent library or API that provides similar functionality, such as the "process" module in the C++ standard library or a cross-platform library like Boost.Process or POCO C++ Libraries. These libraries provide cross-platform options for managing processes in C++ programs and can be used in both Windows and Unix-like systems.
Here's an example using the C++ standard library to achieve similar functionality as "sys/wait.h" for handling child processes:
c++Copy code
#include <iostream>
#include <cstdlib>
#include <unistd.h> // For fork(), execvp(), and exit()
int main() {
pid_t pid = fork();
if (pid == -1) {
// Error occurred
std::cerr << "Fork failed!" << std::endl;
exit(EXIT_FAILURE);
} else if (pid == 0) {
// Child process
std::cout << "Hello from child process!" << std::endl;
// Execute desired child process code here
exit(EXIT_SUCCESS);
} else {
// Parent process
// Wait for child process to complete
int status;
waitpid(pid, &status, 0);
std::cout << "Child process completed with status: " << status << std::endl;
}
return 0;
}