Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I've just discovered the command setsid, which makes life a whole lot easier for running programs from Terminal. What I'd like to know is if there's a way to set programs to launch in a new session automatically, because honestly I'm probably going to be prepending setsid before everything I run now. Is this bad practice for some reason?

share|improve this question
You could try something like this alias foo='setsid foo' and add this to your .bashrc – us3r May 15 '12 at 20:28
Thanks for the suggestion, but that didn't seem to do anything. Other ideas? – Murmur May 15 '12 at 20:35

Apart from creating aliases for your programs, it's not really possible to have setsid automatically prefixed before every command typed in the terminal. However, I find it is very useful to create an .inputrc in your home folder and place in it (observing the quoting):

Control-o: "setsid "

You can now hit Ctrl+o in the terminal and then type your command; it saves a lot of time if you need to keep repeating it. There is no error in the placement of quotes: it allows you to immediately type a command after the shortcut is used. This functionality and much more is provided by bash's readline library: see man bash or the Ubuntu manpages online.

With reference to your second question, it isn't bad practice to use setsid a lot and just depends on your particular needs. In fact it is extremely useful, because, as noted at,

setsid creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session, the process group leader of the new process group, and has no controlling tty...The calling process will be the only process in this new process group and in this new session.

Hence the program launched with setsid has complete independence from the terminal from which it was started, as a new process has been forked.

There are also other similar, but different ways of detaching a program from the terminal such as nohup or disown. (It should be said that setsid is a program from the util-linux package, while disown is a bash builtin.) This question may be of great interest, as it touches upon such related topics:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.