ejemplo de bloquear signals
sigemptyset(&mask1);
sigaddset(&mask1,SIGALRM);
sigprocmask(SIG_BLOCK,&mask1,NULL);
donde NULL podria ser una mask para recibir una copia de la old mask.
donde SIG_BLOCK podria ser SIG_UNBLOCK
tratamiento de errores
include <sys/wait.h>
// PROGRAMADLA para los LABORATORIOS
void trataExitCode(int pid,int exit_code)
{
int exit_code,statcode,signcode;
char buffer[128];
if (WIFEXITED(exit_code)) {
statcode = WEXITSTATUS(exit_code);
sprintf(buffer,“El proceso %d termina con exit code %d\n”, pid,
statcode);
write(1,buffer,strlen(buffer));
}
else {
signcode = WTERMSIG(exit_code);
sprintf(buffer,“El proceso %d termina por el signal %d\n”, pid,
signcode);
write(1,buffer,strlen(buffer));
}
capturar signals
void main()
{
char buffer[128];
struct sigaction trat;
sigset_t mask;
sigemptyset(&mask);
trat.sa_mask=mask;
trat.sa_flags=0;
trat.sa_handler = f_sigint;
sigaction(SIGINT, &trat, NULL); // Cuando llegue SIGINT se ejecutará
// f_sigint
while(1) {
sprintf(buffer,“Estoy haciendo cierta tarea\n”);
write(1,buffer,strlen(buffer));
}
}
void f_sigint(int s)
{
char buffer[128];
sprintf(buffer,“SIGINT RECIBIDO!\n”);
exit(0);
}