Altre piccole correzioni
[gapil.git] / sources / sigwait.c
diff --git a/sources/sigwait.c b/sources/sigwait.c
new file mode 100644 (file)
index 0000000..7dcc983
--- /dev/null
@@ -0,0 +1,66 @@
+/* sigwait.c
+ * 
+ * Copyright (C) 2021 Simone Piccardi
+ * 
+ * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/****************************************************************
+ *
+ * Program sigwait.c: 
+ * Test program for sigwait function
+ *
+ * Author: Simone Piccardi
+ * Nov. 2021
+ *
+ ****************************************************************/
+/* 
+ * Include needed headers
+ */
+#define _GNU_SOURCE
+#include <unistd.h>      /* unix standard library */
+#include <signal.h>      /* signal constants, types and functions */
+#include <errno.h>       /* error definitions and routines */ 
+#include <stdlib.h>      /* C standard library */
+#include <unistd.h>      /* unix standard library */
+#include <stdio.h>      /* standard I/O library */
+#include <string.h>      /* C strings library */
+
+int main(int argc, char *argv[])
+{
+/* 
+ * Variables definition  
+ */
+    int i;
+    pid_t pid = 0;
+    int sig,res;
+    sigset_t set;
+
+    sigemptyset(&set);
+    sigaddset(&set, SIGALRM);
+//    while (1) {
+    res=sigwait(&set, &sig);
+    printf("Sig was %d", sig);
+    if ( res > 0) {
+       printf("Errno was %d", errno);
+       perror("errore");
+       printf("Result was %d", res);
+       printf("Error by res was %s", strerror(res));
+       exit(11);
+    } else {
+       printf("Result was %d", res);
+       printf("Normal exit");
+    }
+//    }
+}