summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWolfgang Draxinger <dw@optores.de>2018-04-11 15:09:14 +0200
committerWolfgang Draxinger <dw@optores.de>2018-04-11 15:09:14 +0200
commitb8205128fb4512c62b56c768d84b3848260fdb29 (patch)
tree806618648638d4f5ed8e372cd86b0e459ba97dd8
downloadstopped_exec-b8205128fb4512c62b56c768d84b3848260fdb29.tar.gz
stopped_exec-b8205128fb4512c62b56c768d84b3848260fdb29.tar.bz2
initial commit
-rw-r--r--Makefile2
-rwxr-xr-xstopped_execbin0 -> 10848 bytes
-rw-r--r--stopped_exec.c36
3 files changed, 38 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..69e152a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,2 @@
+stopped_exec: stopped_exec.c
+ $(CC) -o stopped_exec stopped_exec.c
diff --git a/stopped_exec b/stopped_exec
new file mode 100755
index 0000000..b203be5
--- /dev/null
+++ b/stopped_exec
Binary files differ
diff --git a/stopped_exec.c b/stopped_exec.c
new file mode 100644
index 0000000..2d3ad84
--- /dev/null
+++ b/stopped_exec.c
@@ -0,0 +1,36 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+
+static char const msg_usage[] = "Usage: %s <command> [args]\nExecutes a program in stopped state.\n";
+
+static
+int usage(char const* cmd)
+{
+ fprintf(stderr, msg_usage, cmd);
+ return 1;
+}
+
+int main(int argc, char *argv[])
+{
+ if( 2 > argc ){
+ return usage(argv[0]);
+ }
+ pid_t const fork_rc = fork();
+ if( 0 == fork_rc ){
+ setsid();
+ kill( 0, SIGSTOP );
+ execvp(argv[1], argv+1);
+ perror("execvp");
+ return 2;
+ }
+ if( 0 > fork_rc ){
+ perror("fork");
+ return 3;
+ }
+ fprintf(stderr, "%ld\n", (long)fork_rc);
+ return 0;
+}