Site icon LinuxCommands.site

setsid command tutorial in linux/unix with examples and use cases

Linux setsid command – run a program in a new session

Linux setsid command is usually used when you need to run scripts in the background. It is not affected by the terminal hangup signal.

syntax

setsid [options] program [arguments]

options

Examples & Use Cases

Running jobs (scripts) in the background

Run the ping command using the setsid command and exit the terminal.

➜  ~ setsid ping www.google.com > /dev/null 2>&1 &
[1] 4230
[1]  + 4230 done       setsid ping www.google.com > /dev/null 2>&1
➜  ~ ps -ef | grep ping | grep -v grep
ylspirit   4233      1  0 06:50 ?        00:00:00 ping www.google.com
➜  ~ exit
Connection to 192.168.159.171 closed.

Open a new terminal and use the ps command to see the ping command.

➜  ~ ps -ef | grep ping | grep -v grep
ylspirit   4233      1  0 06:50 ?        00:00:00 ping www.google.com

Exit mobile version