File: thread.cc

package info (click to toggle)
ccbuild 1.5.7-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,208 kB
  • ctags: 441
  • sloc: cpp: 4,817; sh: 1,195; makefile: 53; ansic: 43
file content (50 lines) | stat: -rw-r--r-- 1,352 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
	ccbuild - A strict developer's build utility
	Copyright (C) 2005  A. Bram Neijt <bneijt@gmail.com>

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
#include <iostream>

int main(int argc, char * argv[])
{
	using namespace std;
	int status;
	pid_t p = fork();
	if(p == -1)
		cout << "Failure to fork\n";
	else if(p == 0)
	{
		cout << "Child exiting with 10\n";
		sleep(2);
		exit(5);
	}
	else
	{
		//Mother waits...
		pid_t pp = wait(&status);
		if(pp == p)
			cout << "Got the pid back from wait\n";
		else
			cout << "Got another pid back from wait: " << pp << "\n";
		cout << "Status: " << WEXITSTATUS(status) << "\n";
	}
	return 0;
}