setsid()
public
Establishes this process as a new session and process group leader, with no
controlling tty. Returns the session id. Not available on all platforms.
Process.setsid
Show source
/*
* call-seq:
* Process.setsid => fixnum
*
* Establishes this process as a new session and process group
* leader, with no controlling tty. Returns the session id. Not
* available on all platforms.
*
* Process.setsid #=> 27422
*/
static VALUE
proc_setsid()
{
int pid;
rb_secure(2);
pid = setsid();
if (pid < 0) rb_sys_fail(0);
return INT2FIX(pid);
rb_pid_t pid;
int ret;
rb_secure(2);
pid = getpid();
ret = setpgrp();
/* If `pid_t setpgrp(void)' is equivalent to setsid(),
`ret' will be the same value as `pid', and following open() will fail.
In Linux, `int setpgrp(void)' is equivalent to setpgid(0, 0). */
ret = setpgrp(0, pid);
if (ret == -1) rb_sys_fail(0);
if ((fd = open("/dev/tty", O_RDWR)) >= 0) {
ioctl(fd, TIOCNOTTY, NULL);
close(fd);
}
return INT2FIX(pid);
rb_notimplement();
}