Path: utzoo!news-server.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!unreplyable!garbage From: lin@CS.WMICH.EDU (Lite Lin) Newsgroups: comp.unix.questions Subject: sending signal sends -1 to the receiving process (question) Message-ID: <9103141128.AA12846@cs.wmich.edu> Date: 14 Mar 91 11:28:26 GMT Sender: daemon@tut.cis.ohio-state.edu Lines: 86 Hello, I have a question regarding signals. This question occurs to me when I'm trying to write a curses based package. I'd like certain area on the screen to blink, but SUN terminal does not support blinking (am I right?), so I produce a child process and have the child process interrupt the parent process, say, every 0.2 seconds, and then certain area on the screen changes state accordingly (A related problem is, the visual effect produced in this way is not really pleasing, is there any way to get around the problem?). The problem comes in when I notice that the parent process keeps receiving unwanted characters. This I did not know before; it looks like when a process sends a signal to another process, it puts something in the other process's input stream as well. I tried to write a very much simplified program and then I realized the problem has nothing to do with the cursor package. I can get around the problem because the unwanted character is always (char)(-1), so I simply ignore that, but still I'm wondering what is the reason for this. Anyone care to explain? The programs are appended. BTW, if it is relevant, I'm using a SPARC IPC running SunOS 4.1 and compiled the programs with /usr/5bin/cc and relevant libraries & includes, where appropriate. Thanks in advance, Lite ======================================================================== #include void blink(); main() { int pid; char ch; if ((pid=fork()) == -1) { /* forks off a process which would interrupt once in a while; help do blinking */ perror("fork"); exit(1); } else if (pid == 0) { execl("/sol3/cs1/lin/599/sysv-nopad/nap", "nap", "2000000", (char *)0); perror("execl"); } else signal(SIGALRM, blink); while (ch=getchar()) { printf("%d\n", ch); /* this prints -1 */ printf("%c", ch); } } void blink() { signal(SIGALRM, blink); } ======================================================================== >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #include /* the "nap" program */ #include #include main(argc, argv, envp) int argc; char *argv[], *envp[]; { int usec = 0; char *ptr; int ppid; ppid = getppid(); ptr = argv[1]; while (*ptr) { usec = usec*10 + *ptr - '0'; ptr++; } for (;;) { usleep(usec); kill(ppid, SIGALRM); } } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>