Added manpage for blindtty (by Christoph Berg from Debian)
[retty.git] / blindtty.c
blob5c12ed3a4fe3d39a90f16dfcc32de2941227c52a
1 /*
2 * blindtty - run command in a detached terminal
4 * Usage: blindtty CMD [ARGS]...
6 * You might find it useful to run it as "setsid blindtty CMD...".
8 * Copyright (c) 2006 Petr Baudis, Jan Sembera
9 */
11 #include <pty.h>
12 #include <signal.h>
13 #include <stdio.h>
14 #include <sys/types.h>
15 #include <unistd.h>
18 void
19 sigchld(int s)
21 _exit(0);
24 int
25 main(int argc, char *argv[])
27 int ptm;
28 pid_t pid;
30 if (argc < 2) {
31 fprintf(stderr, "Usage: blindtty CMD [ARG]...\n");
32 return 1;
35 pid = forkpty(&ptm, NULL, NULL, NULL);
36 if (!pid) {
37 int i; for (i=0; i<argc; i++) argv[i] = argv[i+1]; argv[i]=NULL;
38 execvp(argv[0], argv);
39 perror("execvp() failed");
40 return 2;
43 printf("%s started with pid %d\n", argv[1], pid);
45 signal(SIGCHLD, sigchld);
47 while (1) {
48 char buf[1024];
49 if (read(ptm, buf, 1024) <= 0)
50 _exit(0);
53 return 0;