rc

[fork] interactive rc shell
git clone https://hhvn.uk/rc
git clone git://hhvn.uk/rc
Log | Files | Refs | README | LICENSE

mkstatval.c (438B)


      1 #include <stdio.h>
      2 #include <sys/types.h>
      3 #include <sys/wait.h>
      4 #include <unistd.h>
      5 
      6 int main(void) {
      7 	int cstatus, pstatus;
      8 	pid_t pid;
      9 	
     10 	for (cstatus = 0; cstatus < 2; ++cstatus) {
     11 		switch (pid = fork()) {
     12 		case -1:
     13 			perror("fork");
     14 			return 1;
     15 		case 0:
     16 			_exit(cstatus);
     17 		default:
     18 			if (wait(&pstatus) != pid) {
     19 				perror("wait");
     20 				return 1;
     21 			}
     22 			printf("#define STATUS%d %d\n", cstatus, pstatus);
     23 		}
     24 	}
     25 	return 0;
     26 }