aboutsummaryrefslogtreecommitdiff
path: root/myint.c
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-08-11 10:33:39 +0000
committer_ov4 <ov4@ov4.org>2026-08-11 10:33:39 +0000
commit9d8cd99dfa156fa48801aa8bc7821c62d023fe80 (patch)
treeff51e3196dabd1a928962f64a2a05006b5c7f1b3 /myint.c
parent3658a796b6013d2129c0895e9cb994fcdc9662ef (diff)
init
Diffstat (limited to 'myint.c')
-rw-r--r--myint.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/myint.c b/myint.c
new file mode 100644
index 0000000..ea5bee1
--- /dev/null
+++ b/myint.c
@@ -0,0 +1,36 @@
+/*
+ * myint.c - Another handy routine for testing your tiny shell
+ *
+ * usage: myint <n>
+ * Sleeps for <n> seconds and sends SIGINT to itself.
+ *
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <signal.h>
+
+int main(int argc, char **argv)
+{
+ int i, secs;
+ pid_t pid;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <n>\n", argv[0]);
+ exit(0);
+ }
+ secs = atoi(argv[1]);
+
+ for (i=0; i < secs; i++)
+ sleep(1);
+
+ pid = getpid();
+
+ if (kill(pid, SIGINT) < 0)
+ fprintf(stderr, "kill (int) error");
+
+ exit(0);
+
+}