int main(void) { pid_t pid; int status ; if((pid = fork()) < 0) err_sys("fork error"); else if(pid == 0) exit(7); if(wait(&status) != pid) err_sys("wait error"); pr_exit(status); if((pid = fork()) < 0) err_sys("fork error"); else if(pid == 0) abort(); if(wait(&status) != pid) err_sys("wait error"); pr_exit(status); if((pid = fork()) < 0) err_sys("fork error"); else if(pid == 0) status /= 0; if(wait(&status) != pid) err_sys("wait error"); pr_exit(status); exit(0); }
int main(void) { pid_t pid; int status; pid = fork(); if(pid == 0) return 100; wait(&status); pr_exit(status); pid = fork(); if(pid == 0) { char *p = NULL; *p = 'H'; return 0; } wait(&status); pr_exit(status); pid = fork(); if(pid == 0) { int a = 100 / 0; printf("a : %d\n", a); return 0; } wait(&status); pr_exit(status); return 0; }
/* * test driver: * we will fork two processes then call two version of aborts and parent will * print the termination status for them, to see the differences between two * versions of abort. */ int main( int argc, char **argv ) { pid_t pid; int status; if ( (pid = fork()) < 0 ) { err_sys( "fork() error" ); } else if ( pid == 0 ) { printf( "I am child NO1, and I am going by calling abort_normal()\n" ); abort_normal(); } if ( wait( &status ) != pid ) { err_sys( "wait error on processs %d", pid ); } pr_exit( status ); /* Now second version abort verification */ if ( (pid = fork()) < 0 ) { err_sys( "fork() error" ); } else if ( pid == 0 ) { printf( "I am child NO2, and I am going by calling abort_exit()\n" ); abort_exit(); } if ( wait( &status ) != pid ) { err_sys( "wait error on processs %d", pid ); } pr_exit( status ); return 0; }
int main(void) { int status; if ((status = system("date")) < 0) { printf("system() error\n"); exit(-1); } pr_exit(status); if ((status = system("nosuchcommand")) < 0) { printf("system() error\n"); exit(-1); } pr_exit(status); if ((status = system("who; exit 44")) < 0) { printf("system() error\n"); exit(-1); } pr_exit(status); return 0; }
void ss_init(void) { int i, ret; struct rlimit limit; ret = getrlimit(RLIMIT_NOFILE, &limit); if (ret == -1) { pr_err("%s: %s\n", __func__, strerror(errno)); } else { if (limit.rlim_cur < DEFAULT_MAX_CONNECTION) nfds = limit.rlim_cur; } pr_info("%s: max connection: %d\n", __func__, nfds); link_head = calloc(nfds, sizeof(void *)); if (link_head == NULL) pr_exit("%s: calloc failed", __func__); clients = calloc(nfds, sizeof(struct pollfd)); if (clients == NULL) pr_exit("%s: calloc failed", __func__); for (i = 0; i < nfds; i++) clients[i].fd = -1; }
int main(void) { pid_t pid; int status; if ( (pid = fork()) < 0) { perror("fork");exit(-1); } else if (pid == 0) { /* child */ sleep(1); printf("inchild\n"); exit(101); } if (wait(&status) != pid) /* wait for child */ { perror("wait");exit(-2); } printf("in parent\n"); pr_exit(status); /* and print itsstatus */ if ( (pid = fork()) < 0) { perror("fork");exit(-1); } else if (pid == 0) /*child */ abort(); /* generates SIGABRT */ if (wait(&status) != pid) /* wait for child */ { perror("wait");exit(-2); } pr_exit(status); /* and printits status */ if ( (pid = fork()) < 0) { perror("fork");exit(-1); } else if (pid == 0) /*child */ status /= 0; /* divide by 0 generates SIGFPE */ if (wait(&status) != pid) /* wait for child */ { perror("wait");exit(-1); } pr_exit(status); /* and printits status */ exit(0); }
int main(void) { pid_t pid; int status; if ((pid = fork()) < 0) err_sys("fork error"); else if (pid == 0) /* child */ exit(7); if (wait(&status) != pid) /* wait for child */ err_sys("wait error"); pr_exit(status); /* and print its status */ if ((pid = fork()) < 0) err_sys("fork error"); else if (pid == 0) /* child */ abort(); /* generates SIGABRT */ if (wait(&status) != pid) /* wait for child */ err_sys("wait error"); pr_exit(status); /* and print its status */ if ((pid = fork()) < 0) err_sys("fork error"); else if (pid == 0) /* child */ status /= 0; /* divide by 0 generates SIGFPE */ if (wait(&status) != pid) /* wait for child */ err_sys("wait error"); pr_exit(status); /* and print its status */ exit(0); }
int main() { pid_t pid; int status; if((pid = fork()) < 0) perror("fork1 error."); else if(pid == 0) exit(7); if(wait(&status) != pid) perror("wait1 error"); pr_exit(status); if((pid = fork()) < 0) perror("fork2 error"); else if(pid == 0) abort(); if(wait(&status) != pid) perror("wait2 error"); pr_exit(status); if((pid = fork()) < 0) perror("fork3 error"); else if(pid == 0) status /= 0; if(wait(&status) != pid) perror("wait3 error"); pr_exit(status); exit(0); }
int main() { int status=0; if((status=system("date"))<0) err_sys("system() error\n"); pr_exit(status); if((status=system("who; exit 44"))<0) err_sys("system() error\n"); pr_exit(status); exit(0); }
void setnonblocking(int fd) { int opts; if((opts=fcntl(fd,F_GETFL))<0) pr_exit("fcntl F_GETFL"); opts=opts|O_NONBLOCK; if(fcntl(fd,F_SETFL,opts)<0) pr_exit("fcntl F_SETFL"); }
int main(int argc,char *argv[]) { int i,n; int listenfd,connfd,epfd,nfds; struct sockaddr_in servaddr,cliaddr; struct epoll_event ev,events[MAXEVENTS]; bzero(&servaddr,sizeof(servaddr)); if((listenfd=socket(AF_INET,SOCK_STREAM,0))<0) pr_exit("socket"); setnonblocking(listenfd); servaddr.sin_family=AF_INET; servaddr.sin_port=htons(PORT); servaddr.sin_addr.s_addr=htonl(INADDR_ANY); if(bind(listenfd,(struct sockaddr *)&servaddr,sizeof(servaddr))<0) pr_exit("bind"); if(listen(listenfd,LISTENQ)<0) pr_exit("listen"); epfd=epoll_create(MAXEVENTS); ev.data.fd=listenfd; ev.events=EPOLLIN|EPOLLET; if(epoll_ctl(epfd,EPOLL_CTL_ADD,listenfd,&ev)<0) pr_exit("epoll_ctl"); for( ; ; ) { nfds=epoll_wait(epfd,events,MAXEVENTS,-1); for(i=0;i<nfds;i++) { if(events[i].data.fd==listenfd) { socklen_t slen; if((connfd=accept(listenfd,(struct sockaddr *)&cliaddr, &slen))<0) pr_exit("accept"); ev.data.fd=connfd; ev.events=EPOLLIN|EPOLLET; epoll_ctl(epfd,EPOLL_CTL_ADD,connfd,&ev); } if(events[i].events & EPOLLIN) { char buffer[MAXLINE]; bzero(&buffer,MAXLINE); if((n=read(events[i].data.fd,buffer,MAXLINE))>0) { if(buffer[n-1]=='\n') buffer[n-1]='\0'; printf("%s\n",buffer); } } } } }
int main() { int status; if ((status = System("date")) < 0) err_sys("System error"); pr_exit(status); if ((status = System("nosuchcommond")) < 0) err_sys("System error"); pr_exit(status); if ((status = System("who; exit 44")) < 0) err_sys("System error"); pr_exit(status); }
int main() { pid_t pid; int status; if((pid = fork()) < 0) { perror("fork error"); } else if(pid == 0) { exit(7); } if(wait(&status) != pid) { perror("wait error"); } pr_exit(status); if((pid = fork()) < 0) { perror("fork error"); } else if(pid == 0) { abort(); } if(wait(&status) != pid) { perror("wait error"); } pr_exit(status); if((pid = fork()) < 0) { perror("fork error"); } else if(pid == 0) { status /= 0; } if(wait(&status) != pid) { perror("wait error"); } pr_exit(status); return 0; }
static void do_cmd(char *cmd) { struct tms tmsstart; struct tms tmsend; clock_t start; clock_t end; int status; printf("\ncommand: %s\n", cmd); if ((start = times(&tmsstart)) == -1) { err_sys("strart times error"); } if ((status = system(cmd)) < 0) // { err_sys("system error"); } if ((end = times(&tmsend)) == -1) { err_sys("end times error"); } pr_times(end-start, &tmsstart, &tmsend); // pr_exit(status); }
static void do_cmd(char *cmd) { struct tms tms_start, tms_end; clock_t start, end; int status; printf("\ncommand:%s\n", cmd); if((start = times(&tms_start)) == -1) { perror("times"); exit(1); } if((status = system(cmd)) < 0) { printf("system error\n"); exit(1); } if((end = times(&tms_end)) == -1) { perror("times2"); exit(1); } pr_times(end-start, &tms_start, &tms_end); pr_exit(status); }
/*fork process and calls re_execute to exec the args*/ void redirection(char **argv) { char *filename; int status; int t_argc=0; pid_t pid; parse_r_argv(&r_argv,argv,&t_argc); filename = get_file(argv); pid = fork(); switch (pid) { case -1:printf("\nswitch error\n"); exit(20); break; case 0: re_execute(r_argv,filename,argv); break; default: while(pid!=wait(&status)); pr_exit(status); break; } free(filename); }
int main() { int status; if((status=system("date")) < 0) printf("system() error"); pr_exit(status); if((status = system("nosuchcommand")) < 0) printf("system() error"); pr_exit(status); if((status=system("who; exit 44")) < 0) printf("system() error"); pr_exit(status); exit(0); }
int main(int argc,char *argv[]) { int status; pid_t pid; if((pid = fork()) < 0) { err_sys("fork error"); } else if (pid == 0 ) { exit(7); } if(wait(&status) != pid) err_sys("wait error"); pr_exit(status); if((pid = fork()) < 0) { err_sys("fork error"); } else if (pid == 0 ) { abort(); } if(wait(&status) != pid) err_sys("wait error"); pr_exit(status); if((pid = fork()) < 0) { err_sys("fork error"); } else if (pid == 0 ) { status /= 0; } if(wait(&status) != pid) err_sys("wait error"); pr_exit(status); exit(0); }
int main(int argc,char ** argv) { int status; if((status=system("date"))<0) err_sys("system() error"); pr_exit(status); if((status=system("nosuchcommand"))<0) err_sys("system() error"); pr_exit(status); if((status=system("who ;exit 44"))<0) err_sys("system() error"); pr_exit(status); exit(0); }
int main() { int status; printf("running ps with system\n"); if ((status = system("ps -af"))<0) err_exit("system() error"); pr_exit(status, -1); /* 傳遞一個假的PID */ exit(EXIT_SUCCESS); }
int main(int argc,char *argv[]) { int status; if(argc < 2) err_quit("command-line argument required"); if((status = system(argv[1]) ) < 0) err_sys("system() error"); pr_exit(status); exit(0); }
static void sigchld_handler(int sig) { int status; while (waitpid(-1, &status, WNOHANG) > 0) { pr_exit(status); } return; }
int main (void) { int status; if ((status = system ("date")) < 0) err_sys ("system() error"); pr_exit (status); if ((status = system ("nosuchcommand")) < 0) err_sys ("system() error"); pr_exit (status); if ((status = system ("who; exit 44")) < 0) err_sys ("system() error"); pr_exit (status); exit (EXIT_SUCCESS); }
void creat_main() { int ct,BID_ct; int ct_id; int bid_cnt; int total_cnt[2]; int edit_cc; struct BN_LIST *BN_ptr; unsigned char WKpath[PATHSIZE+1]; if ( (BATCH_infof =fileopen(BATCH_INFO,"w+")) == 0) /* DL VT ctrw -> w+ */ { disperr("COULD NOT creat %s",BATCH_INFO); pr_exit(-1); } setmidwin(); clrscr(); BN_ptr= BN_list; for (ct =0; BN_cnt > ct; ct++) { BID_ct= BN_ptr->bnbid_cnt; charfill(Pathbuf,PATHSIZE+1,NULL); strcatl(Pathbuf,Path_bn,"/",BN_ptr->bnptr_bn,NULL); bid_cnt = 0; total_cnt[0] = total_cnt[1] = 0; /* total rec ccount */ for( ct_id=0;BID_ct >ct_id;ct_id++) { charfill(WKpath,PATHSIZE+1,NULL); strcatl(WKpath,Pathbuf,"/.",BN_ptr->bnptr_bid[ct_id],NULL); /* DL VT . added */ if ((Infile= fileopen(WKpath,"r") ) == NULL) { disperr("COULD NOT open fci_file(%s)",WKpath); continue; } edit_cc = edit_data(Create_sel, total_cnt); if (edit_cc == 1) { curpos(0,14); display("FILE= %s",WKpath); rollup(); edit_out(); bid_cnt++; } fileclose(Infile); } BN_ptr++; } resetwin(); fileclose(BATCH_infof); }
int main(void) { pid_t pid; int status; /* *first child:normal exit */ if ((pid = fork()) < 0) err_sys("fork error"); else if (pid == 0){ exit(7); } if (waitpid(pid,&status,0) != pid) err_sys("waitpid error"); pr_exit(status); /* *second child:abnormal exit */ if ((pid = fork()) < 0) err_sys("fork error"); else if (pid == 0) abort(); if (waitpid(pid,&status,0) != pid) err_sys("waitpid error"); pr_exit(status); /* *third child:divide by 0 generates SIGFPE */ if ((pid = fork()) < 0) err_sys("fork error"); else if (pid == 0) status /= 0; if (waitpid(pid,&status,0) != pid) err_sys("waitpid error"); pr_exit(status); exit(0); }
int main(void) { pid_t pid; int a = 1; siginfo_t infop; if ((pid = fork()) < 0) { err_msg("fork error\n"); } else if (0 == pid) { exit(7); } if (waitid(P_PID, pid, &infop, WEXITED) < 0) { err_msg("waitid error\n"); } pr_exit(infop); if ((pid = fork()) < 0) { err_msg("fork error\n"); } else if (0 == pid) { abort(); } if (waitid(P_PID, pid, &infop, WEXITED) < 0) { err_msg("waitid error\n"); } pr_exit(infop); if ((pid = fork()) < 0) { err_msg("fork error\n"); } else if (0 == pid) { a /= 0; } if (waitid(P_PID, pid, &infop, WEXITED) < 0) { err_msg("waitid error\n"); } pr_exit(infop); exit(0); }
int main(void) { int status; printf("begin vfork in function.\n"); function_use_vfork(); if (pid != wait(&status)) { printf("wait error.\n"); } pr_exit(status); return 1; }
int main(void) { int status; if ( (status = system("date")) < 0) err_sys("system() error"); pr_exit(status); write(STDOUT_FILENO, "========================================\n",41); if ( (status = system("nosuchcommand")) < 0) err_sys("system() error"); pr_exit(status); write(STDOUT_FILENO, "========================================\n",41); if ( (status = system("who; exit 44")) < 0) err_sys("system() error"); pr_exit(status); write(STDOUT_FILENO, "========================================\n",41); exit(0); }
int main(void) { pid_t pid; int status; if ((pid = fork()) < 0) { err_sys("fork error."); } else if (pid == 0) { exit(7); } if (wait(&status) != pid) { err_sys("wait error."); } pr_exit(status); if ((pid = fork()) < 0) { err_sys("fork error."); } else if (pid == 0) { abort(); } if (wait(&status) != pid) { err_sys("wait error."); } pr_exit(status); if ((pid = fork()) < 0) { err_sys("fork error."); } else if (pid == 0) { status /= 0; } if (wait(&status) != pid) { err_sys("wait error."); } pr_exit(status); }
/* *********************************************************************** */ void get_creat_fun() { int key; Create_sel =0; if (cmode) { if(camode) Create_sel = 1; else if(ctmode) Create_sel = 2; else Create_sel = 3; } else { for(;;) { disppr("enter function key"); key = gettxchar(FLWR); switch (~key) { case _SKEY1: {Create_sel = 1; break;} case _SKEY2: {Create_sel = 2; break;} case _SKEY3: {Create_sel = 3; break;} case _SKEY4: { continue;} case _SKEY5: { continue;} case _SKEY6: { continue;} case _SKEY7: { continue;} case _SKEY8: { continue;} case _REL: case _RESET: { continue; } case _END: { pr_exit(0); } default: continue; } if (Create_sel) break; } } highnfunc(Create_sel,Createkeys[Create_sel -1]); }