The problem with it is if you use selfid() to print out the process id there is no way for the calling process to identify itself to selfid() by passing an argument because selfid() cannot have input arguments. (Remember that functions whose address gets passed to atexit() cannot have input arguments.)
To get around this declare a global array of char called name (say) i.e., char name[10]; Before a process does anything else it should copy its own name into its copy of this array. Then in selfid you should print out the contents of this array and the process will be correctly identified.
e.g.
In the parent you should have :
main() {
...
...
strcpy(name,"PARENT");
...
...
if (fork()==0) {
/* child1 */
strcpy(name,"CHILD1");
selfid();
...
...
}
...
...
}
selfid() {
printf("%s : My process id is %d\n",name, getpid());
...
}
Pradeep Pappachan