2. Write a C program for each of the following system calls (one per call) which uses the call in a normal manner. Make sure that your program compiles and executes without error. Show the output from each of the programs. Please check for, and report, any errors. Terminate execution on error (do not continue running if a call fails). a) sbrk b) fork c) sched_getaffinity The last one is a bit tricky. The main page has a lot of useful information on the parameters. The cpu_set_t is an opaque type: You are not meant to manipulate it directly. There are macros in sched.h which will set/clear/test members of the set. The man page for CPU_SET(3) describes these. Of particular interest is CPU_ISSET. The number of cores can be found with sysconf(_SC_NJPROCESSORS_ONLN). This is the number of hyperthreads, not the number of raw cores. It is also the size of the CPU mask. #include #include int main() { } long ncores = sysconf(_SC_NPROCESSORS_ONLN); printf("%d cores found\n", ncores); The CPU mask is a list of values which are either 1 or 0 depending on whether the given process is allowed to run on that logical core. You can iterate over possible values: for (i = 0; i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

need help for parts A and C. i use mac terminal. When i tried, i got warnings and errors. Please guide me step by step along with the answer!

2. Write a C program for each of the following system calls (one per call) which uses the
call in a normal manner. Make sure that your program compiles and executes without
error. Show the output from each of the programs.
Please check for, and report, any errors. Terminate execution on error (do not continue
running if a call fails).
a) sbrk
b) fork
c) sched_getaffinity
The last one is a bit tricky. The main page has a lot of useful information on the
parameters. The cpu_set_t is an opaque type: You are not meant to manipulate it
directly. There are macros in sched.h which will set/clear/test members of the set. The
man page for CPU_SET(3) describes these. Of particular interest is CPU_ISSET.
The number of cores can be found with sysconf(_SC_NJPROCESSORS_ONLN). This
is the number of hyperthreads, not the number of raw cores. It is also the size of the
CPU mask.
#include <stdio.h>
#include <unistd.h>
int main()
{
}
long ncores = sysconf(_SC_NPROCESSORS_ONLN);
printf("%d cores found\n", ncores);
The CPU mask is a list of values which are either 1 or 0 depending on whether the
given process is allowed to run on that logical core. You can iterate over possible
values:
for (i = 0; i<ncores; i++)
{
printf("%d ", CPU_ISSET(i, &mask));
}
Transcribed Image Text:2. Write a C program for each of the following system calls (one per call) which uses the call in a normal manner. Make sure that your program compiles and executes without error. Show the output from each of the programs. Please check for, and report, any errors. Terminate execution on error (do not continue running if a call fails). a) sbrk b) fork c) sched_getaffinity The last one is a bit tricky. The main page has a lot of useful information on the parameters. The cpu_set_t is an opaque type: You are not meant to manipulate it directly. There are macros in sched.h which will set/clear/test members of the set. The man page for CPU_SET(3) describes these. Of particular interest is CPU_ISSET. The number of cores can be found with sysconf(_SC_NJPROCESSORS_ONLN). This is the number of hyperthreads, not the number of raw cores. It is also the size of the CPU mask. #include <stdio.h> #include <unistd.h> int main() { } long ncores = sysconf(_SC_NPROCESSORS_ONLN); printf("%d cores found\n", ncores); The CPU mask is a list of values which are either 1 or 0 depending on whether the given process is allowed to run on that logical core. You can iterate over possible values: for (i = 0; i<ncores; i++) { printf("%d ", CPU_ISSET(i, &mask)); }
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education