Hi all,
I have a multithreaded application which i have run in a development board and in PC. My development board is based on a PXA270 processor that runs Linux
2.6.25 kernel and my PC is x86 with linux 2.6.21 kernel.In the application, i am creating 4 threads.I am printing the parent process ID and the self process Id in all the threads including main.
The output shows that in PC,all the threads have same SELF PID and process ID,which means the application is running as a single process.
But in my development board, the SELF PID's of the all the threads differ and parent PID of the threads and self PID of main thread are different. I have posted the code and output i have obtained below.
Code: ##### #include #include #include #include
void *thread1(void*); void *thread2(void*); void *thread3(void*); void *thread4(void*);
int main() { pthread_t tid[3]; int ret; ret=pthread_create(&tid[0],NULL,(void*)&thread1,NULL); ret=pthread_create(&tid[1],NULL,(void*)&thread2,NULL); ret=pthread_create(&tid[2],NULL,(void*)&thread3,NULL); ret=pthread_create(&tid[3],NULL,(void*)&thread4,NULL);
printf("main():Parent ID is %d.Self PID is %d\n",getppid(),getpid()); while(1) { } }
void *thread1(void* arg) { printf("Test thread 1.Parent ID is %d.Self PID is %d\n",getppid (),getpid()); while(1) { } }
void *thread2(void* arg) { printf("Test thread 2.Parent ID is %d.Self PID is %d\n",getppid (),getpid()); while(1) { } }
void *thread3(void* arg) { printf("Test thread 3.Parent ID is %d.Self PID is %d\n",getppid (),getpid()); while(1) { } }
void *thread4(void* arg) { printf("Test thread 4.Parent ID is %d.Self PID is %d\n",getppid (),getpid()); while(1) { } }
Output in Board: ############## /tmp # ./multi_thread Test thread 1.Parent ID is 995.Self PID is 996 Test thread 2.Parent ID is 995.Self PID is 997 Test thread 3.Parent ID is 995.Self PID is 998 Test thread 4.Parent ID is 995.Self PID is 999 main():Parent ID is 701.Self PID is 994
Output in PC: ########### [root@ragha my_learning]# ./multi_thread_pc main():Parent ID is 5828.Self PID is 7193 Test thread 3.Parent ID is 5828.Self PID is 7193 Test thread 2.Parent ID is 5828.Self PID is 7193 Test thread 1.Parent ID is 5828.Self PID is 7193 Test thread 4.Parent ID is 5828.Self PID is 7193