sigHandler

This commit is contained in:
Lorenzo Bianchi 2023-05-16 16:27:20 +02:00
parent 87a7358755
commit 2c0b9a364a
3 changed files with 32 additions and 10 deletions

View File

@ -1,3 +1,3 @@
# Elaborato_SO
sono super iper ghei++plus extra
sono (Edidek) super iper ghei++plus extra

View File

@ -19,14 +19,12 @@ void sigHandlerClient(int sig) {
}
if (sig == SIGTERM) {
//TODO:
//TODO: in teoria non fa niente di speciale qua, in quanto il server dovrebbe chiudere tutto
}
exit(0);
}
int semid;
//TODO: mettere main ma non l'ho fatto per makefile
int client(){
@ -69,7 +67,7 @@ int client(){
// SHM
int shmBoardid = getShmid(input.rows, input.collums);
tile_t *board = shmServerAt(shmBoardid);
tile_t *board = shmClientAt(shmBoardid);
//
// SEM
@ -79,6 +77,7 @@ int client(){
}
//
semOp(semid, 0, -1); // aspetta che il server gli dia il permesso di connettersi

View File

@ -16,16 +16,40 @@
void sigHandlerServer(int sig) {
if (sig == SIGINT) {
//TODO:
// per il secondo SIGINT basta modificare il sig in SIGTERM
}
if (sig == SIGTERM) {
//TODO:
//TODO: killare figli
// msgq
if (msgctl(msgid, IPC_RMID, NULL) == -1) {
errExit("msgctl", "sigHandlerServer");
}
// sem
if (semctl(semid, 0, IPC_RMID, 0) == -1) {
errExit("semctl", "sigHandlerServer");
}
// shm
if (shmdt(board) == -1) {
errExit("shmdt", "sigHandlerServer");
}
if (shmctl(shmid, IPC_RMID, NULL) == -1)
errExit("shmctl", "SigHandlerSever");
}
exit(0);
}
int semid;
int msgid;
int shmid;
tile_t *board;
int main(int argc, char *argv[]){
@ -49,8 +73,7 @@ int main(int argc, char *argv[]){
// MSGQ
key_t msgKey = ftok(KEYFILE, 'M');
int msgid = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR);
if (msgid == -1) {
if (msgid = msgget(msgKey, IPC_CREAT | S_IRUSR | S_IWUSR) == -1){
errExit("msgget", "F4Server");
}
// msg
@ -67,8 +90,8 @@ int main(int argc, char *argv[]){
//
// SHM
int shmBoardid = getShmid(input.rows, input.collums);
tile_t *board = shmServerAt(shmBoardid);
shmid = getShmid(input.rows, input.collums);
board = shmServerAt(shmid);
//
// SEM