printf("Process ID:%ld\n",my_pid); printf("Parent ID:%ld\n",parent_pid); printf("User ID:%ld\n",my_uid); printf("Effective User ID:%ld\n",my_euid); printf("Group ID:%ld\n",my_gid); printf("Effective Group ID:%ld\n",my_egid):
if(my_info) { printf("My Login Name:%s\n" ,my_info->pw_name); printf("My Password :%s\n" ,my_info->pw_passwd); printf("My User ID :%ld\n",my_info->pw_uid); printf("My Group ID :%ld\n",my_info->pw_gid); printf("My Real Name:%s\n" ,my_info->pw_gecos); printf("My Home Dir :%s\n", my_info->pw_dir); printf("My Work Shell:%s\n", my_info->pw_shell); } }
printf("This will demostrate how to get child status\n"); if((child=fork())==-1) { printf("Fork Error :%s\n",strerror(errno)); exit(1); } else if(child==0) { int i; printf("I am the child:%ld\n",getpid()); for(i=0;i<1000000;i++) sin(i); i=5; printf("I exit with %d\n",i); exit(i); } while(((child=wait(&status))==-1)&(errno==EINTR)); if(child==-1) printf("Wait Error:%s\n",strerror(errno)); else if(!status) printf("Child %ld terminated normally return status is zero\n", child); else if(WIFEXITED(status)) printf("Child %ld terminated normally return status is %d\n", child,WEXITSTATUS(status)); else if(WIFSIGNALED(status)) printf("Child %ld terminated due to signal %d znot caught\n", child,WTERMSIG(status)); }