bakerb
10-19-2001, 02:30 PM
Here comes a long one . . .
I am running Red Hat 7.1 with a 2.4.2 kernel on an x86 platform
I am trying to write a program that traps a signal from shutdown. The problem is, I never see a SIGTERM (the signal the man page says I should see) when I run shutdown (shutdown -t 2 -r +1 "Going Down Now"). I can use kill to send my program the iterm signal (kill -s SIGTERM <pid> ) and my program gets it. The man page says that shutdown sends SIGTERM to every proces with 1 <= pid <= MAX_INT. I just don't understand what is going on. I even ran strace to watch the signals comming in to my program. Nothing pops up during shutdown but when I send it by hand, it does. I have attached my code below. If anyone has any idea what I am doing wrong or if anyone knows where the source to shutdown is, I would really appreciate it.
// This program prints out every interupt
// (signal) thrown at it except SIGKILL
// and SIGSTOP
//
// Author: Brian Baker
// Email: brian_j_baker@yahoo.com
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
// Called on any signal execpt SIGKILL and SIGSTOP
void sig_handler(int signal)
{
printf("Signal %d sent.\n", signal);
if (signal == SIGINT) exit(0); // for ctrl-c for easy kill
}
int main ()
{
int i;
struct sigaction sig_struct; // holds info about signal handler for kernel
sig_struct.sa_handler = &sig_handler;
sigemptyset(&sig_struct.sa_mask);
sig_struct.sa_flags = 0;
for (i = 1; i < 32; i++) // For each type of signal . . . (see /usr/include/bits/signum.h)
{
if (i == SIGKILL || i == SIGSTOP) continue; // Except for SIGKILL and SIGSTOP
if ( sigaction(i, &sig_struct, NULL ) == -1 ) // Tell the kernel i can trap this signal
{
perror("Error informing kernel of what signals we want to trap");
exit(1);
}
}
printf("Running\n");
while ( 1 ); // keep the program alive so we can get interupts
return 0;
}
Thank you so much for your time.
Keep on rockin' in the free world,
- bakerb
[ 19 October 2001: Message edited by: bakerb ]
I am running Red Hat 7.1 with a 2.4.2 kernel on an x86 platform
I am trying to write a program that traps a signal from shutdown. The problem is, I never see a SIGTERM (the signal the man page says I should see) when I run shutdown (shutdown -t 2 -r +1 "Going Down Now"). I can use kill to send my program the iterm signal (kill -s SIGTERM <pid> ) and my program gets it. The man page says that shutdown sends SIGTERM to every proces with 1 <= pid <= MAX_INT. I just don't understand what is going on. I even ran strace to watch the signals comming in to my program. Nothing pops up during shutdown but when I send it by hand, it does. I have attached my code below. If anyone has any idea what I am doing wrong or if anyone knows where the source to shutdown is, I would really appreciate it.
// This program prints out every interupt
// (signal) thrown at it except SIGKILL
// and SIGSTOP
//
// Author: Brian Baker
// Email: brian_j_baker@yahoo.com
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
// Called on any signal execpt SIGKILL and SIGSTOP
void sig_handler(int signal)
{
printf("Signal %d sent.\n", signal);
if (signal == SIGINT) exit(0); // for ctrl-c for easy kill
}
int main ()
{
int i;
struct sigaction sig_struct; // holds info about signal handler for kernel
sig_struct.sa_handler = &sig_handler;
sigemptyset(&sig_struct.sa_mask);
sig_struct.sa_flags = 0;
for (i = 1; i < 32; i++) // For each type of signal . . . (see /usr/include/bits/signum.h)
{
if (i == SIGKILL || i == SIGSTOP) continue; // Except for SIGKILL and SIGSTOP
if ( sigaction(i, &sig_struct, NULL ) == -1 ) // Tell the kernel i can trap this signal
{
perror("Error informing kernel of what signals we want to trap");
exit(1);
}
}
printf("Running\n");
while ( 1 ); // keep the program alive so we can get interupts
return 0;
}
Thank you so much for your time.
Keep on rockin' in the free world,
- bakerb
[ 19 October 2001: Message edited by: bakerb ]