#include <sched.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>

int child( void *arg )
{
	static int thread_count = 0;
	printf ("Thread count = %d\n", thread_count);
	++ thread_count;
	return 0;
}

int main( void )
{
	void *stack[4096];
	int i;
	
	for ( i = 0; i < 32768; ++ i )
	{
		clone( child, stack+4096, CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND, 0);
		if ( waitpid( -1, NULL, __WCLONE ) == -1 )
		{
			return 1;
		}
	}
	
	return 0;
}



