Alright, so, I have created a simple signal experiment program.
-Program sets up child signals
-Forks, and prints PID of child
-Child exits
-Parent gets exit signal from child and prints info on the signal
This worked fine and dandy on Ubuntu, and upon porting it over to BSD I am not getting the same results. Any idea how I can get this working?
Ubuntu Code Output:
Code:
PID: 4121
Entering signal handler!
Handling signal 17 at 0x3e800001019
PID: 4121
Signal code: 1
BSD Code Output:
Code:
PID: 11747
Entering signal handler!
Handling signal 20 at 0x0
PID: 0
Signal code: 0
Code:
Code:
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstring>
#include <errno.h>
void signalChild(
int signal, siginfo_t* info, void* notUsed
){
printf("Entering signal handler!\n");
if ( info == NULL )
{
printf("siginfo is NULL...aborting!\n");
exit(1);
}
printf("Handling signal %d at %p\n", signal, info->si_addr);
printf("PID: %d\t \n", info->si_pid);
printf("Signal code: %d\n", info->si_code );
}
int main()
{
struct sigaction child;
sigemptyset ( &child.sa_mask );
child.sa_sigaction = &signalChild;
child.sa_flags = 0;
child.sa_flags = SA_SIGINFO;
if ( sigaction( SIGCHLD, &child, NULL ) == -1 )
{
fprintf( stderr, "Error with signal setup. Errno: %i\n", errno );
exit( 1 );
}
int pid = fork();
if ( pid == 0 )
{
fprintf( stderr, "PID: %i\n", getpid() );
exit(0);
}
sleep( 1 );
exit(0);
}