You are not logged in.

#1 2014-09-09 21:13:30

publicus
Member
Registered: 2014-01-01
Posts: 129

[RESOLVED] How to disown a process?

This is my script (it's part of something larger, but is enough for now):

#!/bin/sh

setsid test_run.sh

What I'm trying to do is to create a proc that runs by itself and deals with its own input/output and doesn't bother my shell or the script from which it is started.  I thought about using nohup, but would prefer to never see the nohup.out file.

When I run the above, I see the output of the running proc displayed and the command line from where I started this becomes unusable.

Last edited by publicus (2014-09-10 15:04:22)

Offline

#2 2014-09-09 21:27:38

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,614

Re: [RESOLVED] How to disown a process?

in zsh, disown -<job>
Bash is probably the same.


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#3 2014-09-09 21:50:05

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [RESOLVED] How to disown a process?

setsid sounds like what you want, you just need to redirect the standard streams.  Depending on what it is you are "disowning" one might not commonly tamper with stdin, but you could do that to.  Just for stdout/stderr you'd do `setsid your_command >/dev/null 2>&1 &`


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#4 2014-09-10 15:04:09

publicus
Member
Registered: 2014-01-01
Posts: 129

Re: [RESOLVED] How to disown a process?

Trilby wrote:

setsid sounds like what you want, you just need to redirect the standard streams.  Depending on what it is you are "disowning" one might not commonly tamper with stdin, but you could do that to.  Just for stdout/stderr you'd do `setsid your_command >/dev/null 2>&1 &`

This worked very well.  Thank you.

Offline

#5 2014-09-10 15:37:45

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,456
Website

Re: [RESOLVED] How to disown a process?

For a really agressive form, I use the following bash function:

hush() {
	(setsid $@ >/dev/null 2>&1) >/dev/null 2>&1
}

This costs an extra subshell, but it also silences the setsid messages about the process number and the exit code when the process completes.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB