create a process

 avatar
tuhuuduc
c_cpp
a year ago
381 B
9
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