Advertisement
LittleFox94

LF OS can now run C++

May 8th, 2020
1,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <unistd.h>
  3.  
  4. int main(int argc, char* argv[]) {
  5.     std::cout << "Hello world! Forking .." << std::endl;
  6.  
  7.     for(int i = 0; i < 4; ++i) {
  8.         int pid = fork();
  9.  
  10.         if(pid == 0) {
  11.             std::cout << "I'm a fork (number " << i << ")" << std::endl;
  12.             return EXIT_SUCCESS;
  13.         }
  14.         else if(pid > 0) {
  15.             std::cout << "Forked to pid " << pid << std::endl;
  16.         }
  17.     }
  18.  
  19.     throw new std::exception();
  20.  
  21.     return EXIT_SUCCESS;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement