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

I can not get the below program to run using linix. I keep getting an error mess

ID: 3851755 • Letter: I

Question

I can not get the below program to run using linix. I keep getting an error message " fatal error: Types.h: no such file or directory #include <types.h> compilation terminated"

Can you please tell me what I need to do to get the program to compile. I know the answer to the question what is out put at line c and line p but I have to be able to get the code to run.

#include <pthread.h>
#include <stdio.h>
#include <types.h>
int value = 0;
void *runner(void *param); /* the thread */
int main(int argc, char *argv[])
{pid t pid;
pthread t tid;
pthread attr t attr;
pid = fork();
if (pid == 0) { /* child process */
pthread attr init(&attr);
pthread create(&tid,&attr,runner,NULL);
pthread join(tid,NULL);
printf("CHILD: value = %d",value); /* LINE C */
}else if (pid > 0) { /* parent process */
wait(NULL);
printf("PARENT: value = %d",value); /* LINE P */
}
}
void *runner(void *param) { value = 5;
pthread exit(0);
}

Explanation / Answer

#include <pthread.h>
#include <stdio.h>
#include<stdlib.h>
#include <sys/types.h> //The Correct Header File is <sys/types.h>
#include <unistd.h>
int value = 0;
void *runner(void *param); /* the thread */
int main(int argc, char *argv[])
{
pid_t pid;
pthread_t tid; // Correct Sysntax is pthread_t
pthread_attr_t attr; //pthread_attr_t Used to identify a thread attribute object
pid = fork();
if (pid == 0)
{ /* child process */
pthread_attr_init(&attr); //Correct Sysntax is pthread_attr_init()
Underscore missing
pthread_create(&tid,&attr,runner,NULL); //Correct Syntax is
pthread_create() Underscore missing
pthread_join(tid,NULL);
printf("CHILD: value = %d",value); /* LINE C */
}
else if (pid > 0)
{ /* parent process */
wait(NULL);
printf("PARENT: value = %d",value); /* LINE P */

}
return 0;
}
void *runner(void *param)
{
value = 5;
pthread_exit(0);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote