UNIX環境高級編程學習之第九章進程關係-創建孤兒進程
/* File: OrphanProcess.c Desc: 創建孤兒進程 父進程終止後,向原子進程發送掛斷信號,又接着發送繼續信號。 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <errno.h> #include <signal.h> #include <sys/types.h> #include <unistd.h> /* 處理接受到的掛斷信號 */ static void sig_hup(int signo) { printf("SIGHUP recvived, pid = %d /n", getpid()); } /* 打印進程ID、父進程ID、進程組ID、前臺進程組ID */ static void pr_ids(char* name) { printf("%s: pid = %d, ppid = %d, pgrp = %d, tpgrp = %d /n", name, getpid(), getppid(), getpgrp(), tcgetpgrp(STDIN_FILENO)); fflush(stdout); } int main( int agrc, char* argv[]) { char c; pid_t pid; pr_ids("parent"); // 打印主進程(父進程)信息 if ((pid = fork()) < 0) { printf("fork error/n"); exit(-1); }else if( pid > 0) /* parent */ {// 在父進程中 sleep(5); exit(0); }else /* child */ {// 在子進程中 pr_ids("child"); signal(SIGHUP, sig_hup); // 綁定掛斷信號 kill(getpid(), SIGTSTP); // 向自己發送停止信號(Ctrl+Z),暫停進程 pr_ids("child"); if (read(STDIN_FILENO, &c, 1) != 1) { printf("read error from controlling TTY, errno = %d/n", errno); } exit(0); } return 0; }
UNIX環境高級編程學習之第十一章線程-線程的創建、退出、等待、取消、分離 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #i
UNIX環境高級編程學習之第五章標準IO-實現查看所有用戶 #include <string.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main(i
UNIX環境高級編程學習之第六章系統數據文件和信息-修改第四章實現的Shell的“ls -l”功能, 加入顯示文件的用戶名和組名 // 只能查看目錄中的所有文件屬性 #include <stdio.h> #include <stdlib.
UNIX環境高級編程學習之第十章信號-信號集的操作,讓進程阻塞SIGQUIT信號 /* File: sigprocmask.c Desc: 信號集的操作,讓進程阻塞SIGQUIT信號 */ #include <stdio.h> #in
UNIX環境高級編程學習之第八章進程控制-用父子進程實現打開kate,返回kate關閉狀態 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unis
UNIX環境高級編程學習之第三章文件IO-文件讀操作 #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include
UNIX環境高級編程學習之第十章信號-信號的基本操作(綁定/忽略/默認/發送) /* File: signal.c Desc: 信號基本操作 */ #include <stdio.h> #include <stdlib.h> #inc
到現在,我Unix,數據庫的掃盲基本完成了,就差網絡這一塊了。從今天開始網絡掃盲。上週五開始看HTTPD的實現,我們的httpd是AA(AA是我們SBE的元老之一)開發的,只要是AA開發的東西,學習一遍都很有收穫。因爲AA是一位非常優秀的