You can use printf or other error messaging functions instead of err_sys if you are finding it difficult to work with the apue.h implementation of err_sys. You may find the code listed below as a good...

1 answer below »
This program must coded in C, but should run on Linux environment.1) Should run on any Linux environment, show screenshots of compiled and executed output2) Do only 2nd question.3) Sample small


You can use printf or other error messaging functions instead of err_sys if you are finding it difficult to work with the apue.h implementation of err_sys. You may find the code listed below as a good example to get an understand of what needs to be done in assignments A07 and A08. #include #include #include #include #include int value = 0; int sum; void *runner(void *param); /*the thread*/ int main (int argc, char *arg[]) { int 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 \n", value); printf ("CHILD: sum = %d \n", sum); } else if (pid > 0) { /*parent process*/ wait(NULL); printf ("PARENT: value = %d \n", value); } } void *runner(void *param) { value = 5; int i; sum = 0; for (i = 0; i <= value; i++) sum += i; pthread_exit(0); } c/c++ programming in a unix environment, cs 3377, assignment 07 1. [25] write a program using the pthreads api that prints “hello, world!” from four threads it creates and prints the ids of the threads along with in the format “hello, world! from thread id : 0” from each of the threads. you can use a global variable to declare the number of threads to be created and set that to 4 for this assignment. 2. [75] fibonacci is a program that generates the fibonacci sequence of a length n specified by the user. the fibonacci sequence is the series of numbers 0, 1, 1, 2, 3, 5, 8, …. it is defined by the following mathematical expression, with x0 and x1 being 0 and 1, respectively: xn = xn-1 + xn-2 runner is a program that takes a positive integer n as a parameter and finds the sum of first n integers. the user will input that positive integer n which will be used by both the runner and the fibonacci program. it should be checked to ensure that a positive number is being entered by the user. the data generated by runner (the sum) and fibonacci (the sequence as an array) will used by the threads and can be saved as a global variable. write a c program that creates two threads to run the fibonacci and the runner processes. threads will indicate the start and the end of their work by printing statements in the format “thread k starting” “thread k finished”, where k is the thread number. when the threads finish, the parent thread will output the results generated by the two threads by printing in the format, “the sum of first 5 numbers is: 15” and “the first 5 numbers in the fibonacci sequence are: 0, 1, 1, 2, 3” if the user had input 5 as the value of n. value;="" i++)="" sum="" +="i;" pthread_exit(0);="" }="" c/c++="" programming="" in="" a="" unix="" environment,="" cs="" 3377,="" assignment="" 07="" 1.="" [25]="" write="" a="" program="" using="" the="" pthreads="" api="" that="" prints="" “hello,="" world!”="" from="" four="" threads="" it="" creates="" and="" prints="" the="" ids="" of="" the="" threads="" along="" with="" in="" the="" format="" “hello,="" world!="" from="" thread="" id="" :="" 0”="" from="" each="" of="" the="" threads.="" you="" can="" use="" a="" global="" variable="" to="" declare="" the="" number="" of="" threads="" to="" be="" created="" and="" set="" that="" to="" 4="" for="" this="" assignment.="" 2.="" [75]="" fibonacci="" is="" a="" program="" that="" generates="" the="" fibonacci="" sequence="" of="" a="" length="" n="" specified="" by="" the="" user.="" the="" fibonacci="" sequence="" is="" the="" series="" of="" numbers="" 0,="" 1,="" 1,="" 2,="" 3,="" 5,="" 8,="" ….="" it="" is="" defined="" by="" the="" following="" mathematical="" expression,="" with="" x0="" and="" x1="" being="" 0="" and="" 1,="" respectively:="" xn="xn-1" +="" xn-2="" runner="" is="" a="" program="" that="" takes="" a="" positive="" integer="" n="" as="" a="" parameter="" and="" finds="" the="" sum="" of="" first="" n="" integers.="" the="" user="" will="" input="" that="" positive="" integer="" n="" which="" will="" be="" used="" by="" both="" the="" runner="" and="" the="" fibonacci="" program.="" it="" should="" be="" checked="" to="" ensure="" that="" a="" positive="" number="" is="" being="" entered="" by="" the="" user.="" the="" data="" generated="" by="" runner="" (the="" sum)="" and="" fibonacci="" (the="" sequence="" as="" an="" array)="" will="" used="" by="" the="" threads="" and="" can="" be="" saved="" as="" a="" global="" variable.="" write="" a="" c="" program="" that="" creates="" two="" threads="" to="" run="" the="" fibonacci="" and="" the="" runner="" processes.="" threads="" will="" indicate="" the="" start="" and="" the="" end="" of="" their="" work="" by="" printing="" statements="" in="" the="" format="" “thread="" k="" starting”="" “thread="" k="" finished”,="" where="" k="" is="" the="" thread="" number.="" when="" the="" threads="" finish,="" the="" parent="" thread="" will="" output="" the="" results="" generated="" by="" the="" two="" threads="" by="" printing="" in="" the="" format,="" “the="" sum="" of="" first="" 5="" numbers="" is:="" 15”="" and="" “the="" first="" 5="" numbers="" in="" the="" fibonacci="" sequence="" are:="" 0,="" 1,="" 1,="" 2,="" 3”="" if="" the="" user="" had="" input="" 5="" as="" the="" value="" of="">
Answered 6 days AfterApr 19, 2021

Answer To: You can use printf or other error messaging functions instead of err_sys if you are finding it...

Ali Asgar answered on Apr 26 2021
158 Votes
/*============================================================================
Description :The
Fibonacci sequence
============================================================================ */
#include
#include
#include
int n; // size of fibonacci sequence.
int *fiboser; // arry holds the value of each fibonacci term.
int i; // counter for the threads.
int sum;
void *fibonacci(void *arg);
void *runner(void *arg);
int main(int argc, char *argv[])
{
if (argc != 2)
{
printf("format is:./a.out \n");
return -1;
} // valdiate num of args.
if (atoi(argv[1]) < 0)
{
printf("%d must be>=0\n", atoi(argv[1]));
return -1;
} //...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here