From 63596b63037b5036772d9152ad959e1049937bbf Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期二, 22 十二月 2020 10:59:09 +0800
Subject: [PATCH] print which one close
---
test/test.c | 68 ++++++++++++++++++----------------
1 files changed, 36 insertions(+), 32 deletions(-)
diff --git a/test/test.c b/test/test.c
index 99e3289..ab21287 100644
--- a/test/test.c
+++ b/test/test.c
@@ -1,35 +1,39 @@
-#include "test.h"
-#define MKEY 0x2222
-int testmatshm() {
-
- int shmid = -1;
- void *shmp;
- shmid = shmget(MKEY, 1024, IPC_CREAT | IPC_EXCL | OBJ_PERMS);
- if (shmid == -1 && errno == EEXIST) {
- printf("first create\n");
- shmid = shmget(MKEY, 0, 0);
- }
-
- if (shmid == -1)
- err_exit(errno, "testmatshm shmget");
-
- shmp = shmat(shmid, NULL, 0);
+#include "usg_common.h"
+static void sig_quit(int);
+int
+main(void)
+{
+ sigset_t
+ newmask, oldmask, pendmask;
+ if (signal(SIGQUIT, sig_quit) == SIG_ERR)
+ err_exit(errno, "can鈥檛 catch SIGQUIT");
+ /*
+ * Block SIGQUIT and save current signal mask.
+ */
+ sigemptyset(&newmask);
+ sigaddset(&newmask, SIGQUIT);
+ if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
+ err_exit(errno, "SIG_BLOCK error");
+ sleep(5);
+ /* SIGQUIT here will remain pending */
+ if (sigpending(&pendmask) < 0)
+ err_exit(errno, "sigpending error");
+ if (sigismember(&pendmask, SIGQUIT))
+ printf("\nSIGQUIT pending\n");
+ /*
+ * Restore signal mask which unblocks SIGQUIT.
+ */
+ if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
+ err_exit(errno, "SIG_SETMASK error");
+ printf("SIGQUIT unblocked\n");
+ sleep(5);
+ exit(0);
+ /* SIGQUIT here will terminate with core file */
}
-typedef struct buf_t { char buf[7]; } buf_t;
-
-void test(int size) {
- char buf[size];
- printf("size = %d\n", sizeof(buf));
+static void sig_quit(int signo)
+{
+ printf("caught SIGQUIT\n");
+ if (signal(SIGQUIT, SIG_DFL) == SIG_ERR)
+ err_exit(errno, "can鈥檛 reset SIGQUIT");
}
-
-char msg[10];
-int main() {
- // testmatshm();
- // testmatshm();
-
- // sleep(60);
-
- // printf("size = %d, msg = %d\n", sizeof(buf_t), sizeof(msg));
- test(12);
-}
\ No newline at end of file
--
Gitblit v1.8.0