int main(void) { char c; pid_t cpid; pr_ids("parent"); if ( (cpid = fork()) < 0) { printf("fork error\n"); perror(NULL); exit(1); } else if (cpid > 0) { sleep(5); exit(0); } pr_ids("child"); signal(SIGHUP, sig_hup); kill(getpid(), SIGTSTP); pr_ids("child"); if (read(STDIN_FILENO, &c, 1) != 1) { printf("read error from control terminal\n"); perror(NULL); exit(1); } printf("read %c from stdin\n", c); exit(0); }
int main(int argc, char const *argv[]) { pid_t pid; int status; if ((pid = fork()) < 0) { perror("fork error"); return -1; } else if (0 == pid) { printf("Child process\n"); pr_ids("child"); sleep(5); exit(EXIT_SUCCESS); } else { printf("Parent Process before waiting\n"); waitpid(pid,&status,WUNTRACED); // block printf("Parent Process After waiting\n"); printf("Parent process\n"); pr_ids("Parent"); } return 0; }
int main(int argc, char* argv[]) { char c; pid_t pid; pr_ids("parent:"); if((pid = fork()) < 0) { printf("fork error"); } else if(pid > 0) { sleep(5); exit(0); } else { pr_ids("child:"); signal(SIGHUP,sig_hup); kill(getpid(),SIGTSTP); pr_ids("child:"); if(read(STDIN_FILENO, &c, 1) != 1) { printf("read error from controlling TTY, errno = %d\n",errno); exit(0); } } }
int main(void) { char c; pid_t pid; pr_ids("parent"); if ((pid = fork()) < 0) { perror("fork error"); exit(1); } else if (pid > 0) { /* parent */ sleep(2); /*sleep to let child stop itself */ exit(0); /* then parent exits */ } else { /* child */ pr_ids("child"); signal(SIGHUP, sig_hup); /* establish signal handler, to prove the orphan process will recieve the SIGHUP sig */ kill(getpid(), SIGTSTP); /* stop ourself, to prove the orphan process will recieve the SIGCONT sig */ sleep(1); pr_ids("child"); /* prints only if we're continued, ppid should change to 1*/ if (read(STDIN_FILENO, &c, 1) != 1) printf("read error from controlling TTY, errno = %d\n", errno); /*the orphan process is in the backgroud so can not read stdin*/ while(1) { printf("in the child\n"); sleep(2); } exit(0); } }
int main(void) { char c; pid_t cpid; pr_ids("parent"); if ( (cpid = fork()) < 0) { printf("fork error\n"); perror(NULL); exit(1); } else if (cpid > 0) { if (setsid() < 0) { printf("setsid error\n"); perror(NULL); exit(1); } sleep(1); exit(0); } pr_ids("child"); sleep(1); setsid(); pr_ids("child"); exit(0); }
int main(int argc,char **argv){ char c; pid_t pid; pr_ids("parent"); if((pid=fork())<0){ err_sys("fork error"); }else if(pid>0){ sleep(5); }else{ pr_ids("child"); signal(SIGHUP, sig_up); kill(getpid(),SIGTSTP); pr_ids("child"); if(read(STDIN_FILENO,&c,1)!=1){ printf("read error %d on controlling TTY\n",errno); } } exit(0); }
int main() { char c; pid_t pid; pr_ids("parent"); if ( (pid = fork()) < 0 ) err_sys("fork error"); else if ( pid > 0 ) sleep(5); else { pr_ids("child"); signal(SIGHUP, sig_hup); kill(getpid(), SIGTSTP); pr_ids("child"); if ( read(STDIN_FILENO, &c, 1) != 1 ) printf("read error %d on controlling TTY\n", errno); } return 0; }
int main(void) { char c; pid_t pid; pr_ids("parent"); if ((pid = fork()) < 0) { err_sys("fork error"); } else if (pid > 0) { /* parent */ sleep(5); /* sleep to let child stop itself */ } else { /* child */ pr_ids("child"); signal(SIGHUP, sig_hup); /* establish signal handler */ kill(getpid(), SIGTSTP); /* stop ourself */ pr_ids("child"); /* prints only if we're continued */ if (read(STDIN_FILENO, &c, 1) != 1) printf("read error %d on controlling TTY\n", errno); } exit(0); }
int main() { char c; pid_t pid; pr_ids("parents"); pid=fork(); if(pid<0) err_sys("fork error"); else if(pid>0) sleep(5); else { pr_ids("child"); signal(SIGHUP,sig_hup);//设置挂断信号SIGHUP消息和消息响应函数 kill(getpid(),SIGTSTP); pr_ids("child"); if(read(STDIN_FILENO,&c,1)!=1) printf("read error %d on controlling TTY\n",errno); } exit(0); }
void pr_tree(py_tree *tree) { if (tree == NULL) return; //printf("good\n"); for (int i = 0; i < LEN; i++) { if (tree->next[i] != NULL) { printf("%d\n", i); pr_tree(tree->next[i]); } } pr_ids(tree->ids); }