create a process
tuhuuduc
c_cpp
2 years ago
381 B
11
Indexable
#include <iostream>
#include <unistd.h>
int main() {
pid_t pid = fork();
if (pid < 0) {
std::cerr << "Error: fork() failed\n";
return 1;
} else if (pid == 0) {
std::cout << "Child process created. PID: " << getpid() << "\n";
} else {
std::cout << "Parent process. Child PID: " << pid << "\n";
}
return 0;
}
Editor is loading...
Leave a Comment