Consultor Eletrônico



Kbase 17080: Sample C Program to Determine the Signals Received
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   12/21/2009
Status: Verified

GOAL:

How to determine what signals are being received by Progress within a UNIX operating environment?

GOAL:

How to determine the signal Progress received?

GOAL:

How to run sigtest.c on UNIX

FACT(s) (Environment):

UNIX
Progress/OpenEdge Versions

FIX:

"sigtst.c" is a "C" program (independent of Progress Software) to determine what signals are being received by a Progress process. This program can be useful in situations where there are reports that closing a window or turning off a terminal is causing the Progress database broker to shut down (when in fact, this type of activity should be sending a hangup signal to the Progress process). With the use of sigtst, you can find out what signal is being sent when a terminal window is closed or the terminal is shut off. To compile sigtst.c, save the "C" source code below to a file called "sigtst.c" and use the compile syntax below:

cc sigtst.c -o sigtst

or

gcc -ansi sigtst.c -o sigtst

Type in "sigtst" at the UNIX command prompt to run the program. When sigtst is run, it returns its process ID (PID) to the screen. Signals received by that process are recorded in a file called "sigtst.out".
Run sigtst, then shut off the terminal it was run from. Look in the sigtst.out file to see which UNIX signal was sent. Was it a hangup signal (signal number 1) or some other signal? To test other signals you can issue a UNIX KILL command to the process ID (PID) listed, and the signal will be recorded in sigtst.out test file. A kill -9 will terminate the program.

The source code of the sigtst.c follows:

#include <fcntl.h>
#include <errno.h>
/* program that prints out signals that is receives. This will loop forever until a kill -9 is sent to it */

void sighdl(); /* signal handler */
int fd = 0; /* global file descriptor */

main()
{
int i;

/* open the output file */
fd = open("sigtst.out",O_RDWR | O_CREAT, 0666);
if (fd < 0)
{
printf("Unable to open sigtst.out, errno = %d\n",errno);
exit(1);
}

/* give us a process number to signal */
printf("Process id is %d\n",getpid());

/* set up handlers for all signals */
for (i=1; i<32; i++)
{
signal(i,sighdl);
}

/* loop until kill -9 */
while (1)
sleep(1);
}

void
sighdl(sigcode)
int sigcode;
{
char buf[80]; /* temp buffer to write output */

if (fd <= 0)
{
printf("output file not open, using stdout\n");
printf("Received signal %d\n",sigcode);
return;
}

signal(sigcode,sighdl);

/* clear the buffer */
memset(buf,'\0',80);

/* setup the buffer */
sprintf(buf,"Received signal %d\n",sigcode);
write(fd,buf,sizeof(buf));
return;
}