/*
 * ej4.c
 * 
 * Copyright 2026 osboxes <osboxes@osboxes>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 * 
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>

int m[4][3] = {{1,2,3},{4,5,6},{7,8,9},{10,11,12}};
int t[4],f=0;
void fusr1(int);
void fusr2(int);
int fs(int *,int);

int main(int argc, char **argv) {
	signal(SIGUSR1,fusr1);
	signal(SIGUSR2,fusr2);
	raise(SIGUSR1);raise(SIGUSR2);
	raise(SIGUSR1);raise(SIGUSR2);
	//pause();
	printf("%d\n",fs(&t[0],4));
	return 0;
}

void fusr1(int s) {
	t[f]=fs(&m[f][0],3);
}
void fusr2(int s) {
	t[f+1]=fs(&m[f+1][0],3);
	f+=2;
}
int fs(int *p,int n) {
	int i,t=0;
	for(i=0;i<n;i++,p++) t+=*p;
	return t;
}
