feat(lab2): unix lab2 done
Lab 2 is in fact the first lab in the set of ones we actually do. It's not particularly hard, but consumed some time for me
This commit is contained in:
47
OSs/lab2/unix/part-A/son.c
Normal file
47
OSs/lab2/unix/part-A/son.c
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* "THE CHEESE-WARE LICENSE" (Revision 1):
|
||||
* <ElectronixTM> wrote this file. As long as you retain this notice
|
||||
* you can do whatever you want with this stuff. If we meet some day,
|
||||
* and you think this stuff is worth it, you can buy me some cheese
|
||||
* in return
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#define PROG_PREFIX "son: "
|
||||
#define log(fmt, args...) printf(PROG_PREFIX fmt "\n", ##args)
|
||||
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
log("\n"
|
||||
"HEEEEEY, father\n"
|
||||
"There's an endless road to rediscover\n"
|
||||
"HEEEEEY, sister\n"
|
||||
"Do you still belive in love I wonder");
|
||||
if (argc != 2) {
|
||||
log("Ooops, wrong amount of args, %d", argc);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
long mode = strtol(argv[1], NULL, 10);
|
||||
log("mode: %ld", mode);
|
||||
switch(mode) {
|
||||
case WAIT_FOR_CHILD:
|
||||
log("pid %d ppid %d", getpid(), getppid());
|
||||
sleep(5);
|
||||
break;
|
||||
case DONT_WAIT_FOR_CHILD:
|
||||
log("before parent die: pid %d ppid %d", getpid(), getppid());
|
||||
sleep(5);
|
||||
log("after parent die: pid %d ppid %d", getpid(), getppid());
|
||||
break;
|
||||
case ZOMBIE_PROCESS:
|
||||
break;
|
||||
default:
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user