create a process

 avatar
tuhuuduc
c_cpp
a month ago
381 B
4
Indexable
Never
#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;
}
Leave a Comment