The C Program
This is the source of the C program whose compiled executable we want to run in a docker container:
#include <stdio.h>
#include <unistd.h>
#include <sys/utsname.h>
int main() {
printf("This program runs in (or as?) a container\n");
printf("The processid (PID) is %d\n", getpid());
struct utsname unam;
if (uname(&unam) != -1) {
printf("Kernel version and release:\n %s\n %s\n", unam.version, unam.release);
} else {
printf("Failed to retrieve kernel information.\n");
}
}
Compiling the program
We need to compile the program. I believe the -static
flag is rather important because SCRATCH
comes empty, i. e. without any C standard libraries. (But I should verify this assumption of mine):
gcc -static prog.c -o prog