00001 /* 00002 Display session- and process-group-related information 00003 AUP2, Sec. 4.03.5 00004 00005 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00006 May be copied only for purposes and under conditions described 00007 on the Web page www.basepath.com/aup/copyright.htm. 00008 00009 The Example Files are provided "as is," without any warranty; 00010 without even the implied warranty of merchantability or fitness 00011 for a particular purpose. The author and his publisher are not 00012 responsible for any damages, direct or incidental, resulting 00013 from the use or non-use of these Example Files. 00014 00015 The Example Files may contain defects, and some contain deliberate 00016 coding mistakes that were included for educational reasons. 00017 You are responsible for determining if and how the Example Files 00018 are to be used. 00019 00020 */ 00021 #include "defs.h" 00022 00023 /*[showpginfo]*/ 00024 #include <termios.h> 00025 00026 static void showpginfo(const char *msg) 00027 { 00028 int fd; 00029 00030 printf("%s\n", msg); 00031 printf("\tprocess ID = %ld; parent = %ld\n", 00032 (long)getpid(), (long)getppid()); 00033 printf("\tsession ID = %ld; process-group ID = %ld\n", 00034 (long)getsid(0), (long)getpgid(0)); 00035 ec_neg1( fd = open("/dev/tty", O_RDWR) ) 00036 printf("\tcontrolling terminal's foreground process-group ID = %ld\n", 00037 (long)tcgetpgrp(fd)); 00038 #if _XOPEN_VERSION >= 4 00039 printf("\tcontrolling-terminal's session ID = %ld\n", 00040 (long)tcgetsid(fd)); 00041 #else 00042 printf("\tcontrolling-terminal's session ID = %ld\n", 00043 (long)getsid(tcgetpgrp(fd))); 00044 #endif 00045 ec_neg1( close(fd) ) 00046 return; 00047 00048 EC_CLEANUP_BGN 00049 EC_FLUSH("showpginfo") 00050 EC_CLEANUP_END 00051 } 00052 /*[catchsig]*/ 00053 static void catchsig(int signo) 00054 { 00055 if (signo == SIGCONT) 00056 showpginfo("got SIGCONT"); 00057 } 00058 /*[main]*/ 00059 int main(void) 00060 { 00061 struct sigaction act; 00062 00063 memset(&act, 0, sizeof(act)); 00064 act.sa_handler = catchsig; 00065 ec_neg1( sigaction(SIGCONT, &act, NULL) ) 00066 showpginfo("initial call"); 00067 while (true) 00068 sleep(10000); 00069 EC_CLEANUP_BGN 00070 exit(EXIT_FAILURE); 00071 EC_CLEANUP_END 00072 } 00073 /*[]*/