A POSIX system call to create a new session and set the process group ID
Questions tagged [setsid]
20 questions
16
votes
1 answer
Difference between subprocess.Popen preexec_fn and start_new_session in python
What is the difference between these two options to start a new process with subprocess.Popen for python3.2+ under Linux:
proc = subprocess.Popen(args, ..., preexec_fn=os.setsid) # 1
proc = subprocess.Popen(args, ..., start_new_session=True) #…

Mikhail Geyer
- 881
- 2
- 9
- 27
6
votes
3 answers
Why use os.setsid() in Python?
I know os.setsid() is to change the process(forked) group id to itself, but why we need it?
I can see some answer from Google is:
To keep the child process running while the parent process exit.
But according to my test below, without os.setsid()…

Edwin
- 71
- 1
- 1
- 3
4
votes
1 answer
Calling setsid() at proc created by posix_spawn()
This question is follow-up for this question.
When the bash command is issued by posix_spawn() I get the message:
bash: no job control in this shell
I think is because in the fork sequence there is call to the function setsid() and I don't know…

AZur
- 39
- 6
3
votes
0 answers
Stop a process started by setsid Debian 8
I ran a js script using
setsid forever sell.js
and I don't know how to stop the script.
I read similar articles but I just don't understand them as I'm fairly new to Linux.

Ḉònnòŕ Ranahan
- 53
- 6
3
votes
2 answers
Handling ctrl + c in perl when script ran using setsid
My Perl script looks like this
A.pl
#!/usr/bin/perl
system("perl ctrlc.pl");
ctrlc.pl
sub signal_handler {
print "Niraj";
}
$SIG{INT} = \&signal_handler;
print "Enter number";
my $no1 = <>;
When I run perl A.pl and press Ctrl-C it is…

Niraj Nandane
- 1,318
- 1
- 13
- 24
3
votes
2 answers
bash setsid nohup ./prog & -- $! not pointed at child process
I was trying to get pid of process I ran with setsid and which ought to run in background like this:
test.sh:
#/bin/bash
setsid nohup ./my_program &
echo $!
if I run ./test.sh it will print a pid of my_program process and it's exactly what I need.…

PepeHands
- 1,368
- 5
- 20
- 36
3
votes
0 answers
Linux: attach a script to controlling terminal after setsid
If I run a Bash script via the setsid command, its controlling terminal will not be attached to any device (it will show up as "?").
Is there a way to re-attach the controlling terminal to some free pts device from a shell script.
Will I be able…

Tomek
- 621
- 1
- 6
- 16
3
votes
2 answers
why setsid could not exit from shell script?
$ cat test1.sh
#!/bin/bash
setsid sleep 100
'test1.sh' shell script will not exit at once.
$ cat test2.sh
#!/bin/bash
setsid sleep 100 &
'test2.sh' shell script will exit at once.
Could anyone explain for me? Thanks a lot.

user3015856
- 91
- 4
2
votes
2 answers
finding the process group id created through setsid
In a shell script, I see that using setsid, we could create a new process group. I am not able to find a reliable way to get the group id after the creation. My requirement is simple, launch a process, and after it is done, clean up any descendant…

melchi
- 627
- 6
- 10
2
votes
1 answer
Why is this command substitution waiting for the background job to finish?
I'm trying to get the PID of a background job with command substitution. The background job is started with setsid. The problem is that the parent process is struck at the command substitution.
Here is an example script:
#!/bin/bash
if [ "$1" =…

phkb
- 143
- 1
- 5
2
votes
1 answer
Why call setsid after fork?
This is a question about an answer to Praveen Gollakota's answer in another question (is this the way I'm supposed to get around comment privileges?).
His answer to the question of why fork twice is, in essence, to make sure the forked process is…

onlyanegg
- 517
- 7
- 15
2
votes
1 answer
is there a way to tell if a process is a child if it did fork and then setsid
If a process did fork then child did setsid, is there any way to tell that it was the child of the first process? Is there any way to kill such process together with its parent?

ren
- 3,843
- 9
- 50
- 95
1
vote
1 answer
Nodejs setsid() equivalent
I'm trying to exec a bash shell in nodejs - which I have working except for job control. I'm pretty sure this is because the spawned process is not being set to the process leader. In C, I was able to do this by calling setsid(). In nodejs, I read…

Amanda Liem
- 45
- 6
1
vote
2 answers
debug a process with gdb and close the terminal
I have a bug in my application which runs on a remote server. After a few hours of execution, the application gets a SIGSEGV and terminates.
I want to debug my remote application with gdb through ssh so when the program gets SIGSEGV gdb will halt…

Boris Lenin
- 21
- 1
1
vote
1 answer
How to terminate the daemon initialized by setsid?
I start a process (a websocket server) using setsid command:
setsid python mod_pywebsocket/standalone.py -p 12345
But how can I stop it? I am sure it is now running just don't know how to get the pid and kill it.

Xi Yu
- 11
- 2