Code:
#include <stdio.h> #include <stdlib.h> #include <assert.h> #define NDEBUG /* 2MB memory all filled with 0 */ #define KB (1024) #define MB (KB*KB) #define MEM_SIZE (2*MB) char memory[MEM_SIZE];
#include <stdio.h> #include <stdlib.h> #include <assert.h> #define NDEBUG /* 2MB memory all filled with 0 */ #define KB (1024) #define MB (KB*KB) #define MEM_SIZE (2*MB) char memory[MEM_SIZE];
while (getppid()!=1) //One is the pid of init and if the parent dies new ppid = 1 { sleep(10); } //do the rest work here //THis will ensure that the child does not do any work until it is adopted by init
int main() { pid_t pids[4] = {0,0,0,0}; //be careful with these pid_t parentid,childid,myid; int i; //why do you want to initialize these with 4 int status; parentid = getpid(); //this is the original pid of the parent for( i =0 ;i < 4 ;i++) { myid = getpid(); if (myid == parentid) //only the parent forks
Leave a comment: