/MY PROGRAM ARE COMPILED IN FEDORA15 ..WITH 4.6 gcc compiler...../
/*A program to see weither stack of threads exist in process creating these threads..or out of process...........*/
2 //QUES ARISES///
3 //PROCESS REPLACED IN THREAD WILL OPERATE ON WHICH CORE...AT THE CORE OF THREAD..OR AT THE CORE OF PROCESS WHICH IS REPLACED....?//
4 //WHAT IS HYPERTHREADING?//
5 #include<stdio.h>
6 #include<unistd.h>
7 #include<stdlib.h>
8 #include<fcntl.h>
9 #include<string.h>
10 #include<pthread.h>
11 void* pthread_fun(void* arg)
12 {
13 char rd[4],wr[4];
14 int ret,fd[2];
15 ret=pipe(fd);
16 if(ret==0)
17 {
18 printf("pipe is created\n");
19 }
20 //printf("fd[0]=%d fd[1]=%d\n",fd[0],fd[1]);
21 sprintf(rd,"%d",fd[0]);
22 sprintf(wr,"%d",fd[1]);
23 //printf("rd=%s wr=%s \n",rd,wr);
24 execl("./cl","cl",rd,wr,NULL);//AS AT THE MOMENT WHEN PCB IS REPLACED....PTHREAD_JOIN S TOPS TO DO ITS WAITING ...FOR THIS THREAD..AFTR THAT SLEEP MAY MAKE WAIT TO PARENT TO C OMPLETE ...THIS REPLACED PROCESS..IN THIS THREAD...
42 pthread_join(tid,&retval);//AFTER CREATING THREAD...IT WILL GOTO WAIT USING pthrea_join
43 //but when pcb is replaced...pthread_join has left its execution in then mid;;;;
44 printf("RETVAL=%s\n",(char*)retval);//all pcb is replaced either it is stack..it proves that ....ALL THE STACKS OF THREAD EXIST IN CURRENT EXISTNG STACK OF PROCESS....STACK OF THREADS ALSO REPLACED BY REPLACING STACK OF PROCESS....SO THIS STATEMENT WILL NOT EXEC UTE DUE TO execl USED IN THREAD....
/* Here we make execl call from child process and as child process do not have its own process context and shared the process context of the parent process than when the child process is replaced by the new process, new process context is formed for the new process and new process use the PCB of the child process. */
Replaced process :
#include<stdio.h>
int main(int argc, char * argv[])
{
char ch;
int fd,i=1;
printf("fd received from calling process is %s",argv[0]);