Just have a query about Status of Child processes created with fork()
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/wait.h>
int main (){
int pid;
int status;
printf("Parent: %d\n", getpid());
pid = fork();
if (pid == 0){
printf("Child %d\n", getpid());
sleep(4);
exit(1);
}
waitpid(pid, &status, 0);
printf("The status of child is %u\n",status);
printf("Parent: %d\n", getpid());
return 0;
}
I expect the status to print 1 , but it prints 256(a byte of 0's is added )
Can someone explain why is this? I am a newbie to C , so please excuse as this question may appear silly to the experts.