?? fork_test.cpp
字號:
#include <iostream>#include <string>#include <sys/types.h>#include <unistd.h>using namespace std;int globalVariable = 2;main (){ string sIdentifier; int iStackVariable = 20; // struct task_struct task; pid_t pID = fork(); if (pID == 0) // child { // Code only executed by child process sIdentifier = "Child Process: "; globalVariable++; iStackVariable++; } else if (pID < 0) // failed to fork { cerr << "Failed to fork" << endl; exit(1); // Throw exception } else // parent { // Code only executed by parent process sIdentifier = "Parent Process:"; } // Code executed by both parent and child. cout << sIdentifier; cout << " Global variable: " << globalVariable; cout << " Stack variable: " << iStackVariable << endl; int temp; temp=getpid(); cout<<"pid: "<<temp<<endl; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -