blob: 1b98315cb53e429b1598ce7d224809a80e79133d [file] [log] [blame]
Rob Landley50239702010-01-05 13:17:47 -06001/* vi: set sw=4 ts=4:
2 *
3 * setsid.c - Run program in a new session ID.
4 *
5 * Copyright 2006 Rob Landley <rob@landley.net>
6 *
Rob Landley9317c062012-03-06 20:48:27 -06007 * Not in SUSv4.
Rob Landley50239702010-01-05 13:17:47 -06008
9USE_SETSID(NEWTOY(setsid, "^<1t", TOYFLAG_USR|TOYFLAG_BIN))
10
11config SETSID
12 bool "setsid"
13 default y
14 help
15 usage: setsid [-t] command [args...]
16
17 Run process in a new session.
18
19 -t Grab tty (become foreground process, receiving keyboard signals)
20*/
21
22#include "toys.h"
23
24void setsid_main(void)
25{
26 while (setsid()<0)
27 if (vfork()) _exit(0);
28 if (toys.optflags) {
29 setpgid(0,0);
30 tcsetpgrp(0, getpid());
31 }
32 xexec(toys.optargs);
33}