Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

wirte c program in linux os two process the initial parnt and another one . the

ID: 3728202 • Letter: W

Question

wirte c program in linux os two process the initial parnt and another one . the parnt process global array with the value : 2,5,6,7,8,9 . another process maulti with array 2 value . after the parnt process and other process both print the array values. the other process will crate theard after pirnting and send your name to theard as a parameter then print it inside the thread along with process id of the thread . also ,   the process should wait for a thread to finshits execution


#include<stdio.h>
#include<stdlib.h>
#include <pthread.h>
#include<sys/wait.h>

the header of funciton if you want it is :
void *funcition ( void*p)
the print statment c languge is : printf ( "some string with specifier " ) ;

Explanation / Answer

#include<stdio.h>
#include<pthread.h>
#include<sys/types.h>
#include <stdlib.h>
int arr1[]={2,5,6,7,8,9};
int arr2[]={-2,-5,-6,-7,-8,-9};

void *t1_function(void *arg)
{
char *name=(char*)arg;
printf(" Name:%s Process_ID:%d",name,getpid());
}

int main()
{
pid_t pid=10;
pid=fork();
int i;
if(pid==0)
{
     pthread_t t;
     char *name="Prashant";
  for(i=0;i<6;i++)
      printf(" From Other Process__Array-2[%d]:%d",i+1,arr2[i]);
  pthread_create(&t,NULL,t1_function,(void*)name);
  pthread_join(t,NULL);
}
else
{
  for(i=0;i<6;i++)
   printf(" From Parent Process__Array-1[%d]:%d",i+1,arr1[i]);
  printf(" --------------------------------------------------------- ");
}
return 1;
}