/* * Copyright (C) 2004 Aleksandar Colovic * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ #include #include #include #include #include #include #include using namespace std; static pid_t nChildPID = 0; void* doWork(void* pArg) { nChildPID = fork (); if (0 == nChildPID) exit(0); return 0; } int main (int argc, char* const argv[]) { pthread_t hThread; pthread_create(&hThread, 0, &doWork, 0); pthread_join(hThread, 0); pid_t pid = -1; if (0 >= (pid = waitpid(nChildPID, 0, 0))) perror("waitpid failed: "); else { assert(pid == nChildPID); cout << "waitpid successfull!" << endl; } return 0; };