Task: System Call Wrappers
Enter the chapters/software-stack/system-calls/syscall-wrapper/drills/tasks/support/ folder and go through the practice items below.
-
Update the files in the
support/folder to makereadsystem call available as a wrapper. Make a call to thereadsystem call to read data from standard input in a buffer. Then callwrite()to print data from that buffer.Note that the
readsystem call returns the number of bytesread. Use that as the argument to the subsequentwritecall that prints read data.We can see that it’s easier to have wrapper calls and write most of the code in C than in assembly language.
-
Update the files in the
support/folder to make thegetpidsystem call available as a wrapper. Create a function with the signatureunsigned int itoa(int n, char *a)that converts an integer to a string. It returns the number of digits in the string. For example, it will convert the number1234to the string"1234"string (NULL-terminated, 5 bytes long); the return value is4(the number of digits of the"1234"string).Then make the call to
getpid; it gets no arguments and returns an integer (the PID - *process ID- of the current process).
If you’re having difficulties solving this exercise, go through this reading material.