Old old Unix: detach from tty

George Shuklin
OpsOps
Published in
1 min readMay 15, 2022

You may feel like a yaml warrior, shoveling deployments and playbooks, but there is an old grumpy Unix underneath. Not knowing it may cause a lot of pain in simple cases. I would like to mock newcomers about it, but I, myself become entangled in it occasionally.

I wanted a simple thing: to detach a new process from tty. I wanted it as a way around readpassword. I really wanted it to read password from stdin, and it really wants to read it from tty no matter what.

If you ever google about ‘disable tty’, good luck to find the answer. If you ever go into ‘pseudoterminal’ research, I’ll wait you for your for few decades with added white hairs.

Basically, it’s all coming down to ‘controlling terminal’, not to ‘tty’.

The answer I found is setsid, which creates a new session, therefore, detaching process from current tty. It’s not obvious that ‘new session’ equals to ‘detach’, but it is.

Basically, the answer is setsid your_binary .

But this is too short for the article so I’ve thrown few grumbles and mocks in.

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.