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
|
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
void *loop()
{
while(1);
}
int main(int argc, char **argv) {
int i = 0;
int num_threads = 1;
if (argc == 2) num_threads = atoi(argv[1]);
printf("Process PID: %d\n", getpid() );
for (i=0; i<num_threads; i++)
{
pthread_t thread;
int ret;
if ((ret = pthread_create(&thread, NULL, loop, NULL)) != 0)
{
printf("pthread_create() failed. Error code %d\n", ret);
exit(1);
}
}
printf("Press ENTER to exit...");
getchar();
return 0;
}
|