Exercising the exec system function, barebones
When a linux process calls the exec system function, it self-transformatively "turns itself into" the object of the exec; its code content gets replaced. This exercise calls upon you to write code to exercise this feature barebones, and out of any other context (that is, exec is usually used together with fork but here we want to look at it all by itself).
Watch the slides/videos that accompany this exercise. Be guided by the code
examples seen there.
The exercise to perform:
Create a subdirectory under your home directory in which to work:
mkdir ~/process-creation
cd ~/process-creation
In a file named "myname.c" write a C program containing a single line in the main function that prints your first name followed by a newline.
In a file named "greeting.c" write a C program containing two lines, one that prints "My name is " followed by a newline, the second that execs myname (i.e., supplies
"myname" as argument to the exec system function).
Compile them:
gcc myname.c -o myname
gcc greeting.c -o greeting
Run greeting:
./greeting
Your file population and execution outcome should look like my screenshot here:
root@instructor process-creation]# ls -1
greeting
greeting.c
myname
myname.c
[root@instructor process-creation]#
[root@instructor process-creation]#
[root@instructor process-creation]# ./greeting
My name is
David
[root@instructor process-creation]#
To turn in:
Zip your two source files, myname.c and greeting.c, into a file named execpractice.zip. Upload it. I will grade it by replacing your "myname" executable with
mine, an identically named executable file that prints some text that I'll
choose. I will make sure that when I run
your code my code runs.