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

View File

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