Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
exec vs. nohup
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Kenneth Bull  
View profile  
 More options Mar 22 2012, 6:29 pm
Newsgroups: comp.unix.programmer, comp.unix.shell
From: Kenneth Bull <kenneth.b...@gmail.com>
Date: Thu, 22 Mar 2012 15:29:43 -0700 (PDT)
Local: Thurs, Mar 22 2012 6:29 pm
Subject: exec vs. nohup
So I have a script with the following line after the shebang:

exec >& file.out
## some echo statements after this

Then I call the script with

nohup ./script &> /dev/null

And the echo statements are making their way to file.out.
So my question is ....
Woudln't nohup check the script's "initial(i.e. before exec)" status
of having stdout/stderr being pointed to terminal, and then force the
script to redirect to /dev/null?  How is the exec that happens later
able to override this?

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rainer Weikusat  
View profile  
 More options Mar 22 2012, 6:42 pm
Newsgroups: comp.unix.programmer, comp.unix.shell
Followup-To: comp.unix.programmer
From: Rainer Weikusat <rweiku...@mssgmbh.com>
Date: Thu, 22 Mar 2012 22:42:52 +0000
Local: Thurs, Mar 22 2012 6:42 pm
Subject: Re: exec vs. nohup

Because it happens later: The shell which executes the nohup
... redirects file descriptors 1 (stdout) and 2 (stderr) to
/dev/null. Then, the script is executed which redirects the same two
file descriptors to file.out. Hence, output goes to this file.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gordon Burditt  
View profile  
 More options Mar 22 2012, 7:44 pm
Newsgroups: comp.unix.programmer, comp.unix.shell
From: gordonb.y3...@burditt.org (Gordon Burditt)
Date: Thu, 22 Mar 2012 18:44:15 -0500
Local: Thurs, Mar 22 2012 7:44 pm
Subject: Re: exec vs. nohup
> So I have a script with the following line after the shebang:

It would help if you'd quote the shebang.

> exec >& file.out
> ## some echo statements after this

> Then I call the script with

> nohup ./script &> /dev/null

I don't understand the &> construct here.  Did you mean >&, and
you're using the C shell?  If not, what shell are you using to
invoke the script, what shell are you using to run the script, and
what does &> mean?

Under bash, that line would put
        nohup ./script
into the background, and treats
        > /dev/null
as a command and runs it in the foreground.  This makes very little
sense (although a command like > foo.tmp would create the file
foo.tmp, but /dev/null presumably already exists).

> And the echo statements are making their way to file.out.
> So my question is ....
> Woudln't nohup check the script's "initial(i.e. before exec)" status
> of having stdout/stderr being pointed to terminal, and then force the
> script to redirect to /dev/null?  

No.  Redirections on a command line are a function of the shell,
not nohup (even if nohup is a shell built-in).  They take effect
before nohup is executed.  nohup's initial stdout and stderr are
pointed at /dev/null.

If nohup's initial stdout/stderr *were* a terminal, nohup would
redirect them to the file nohup.out.

> How is the exec that happens later
> able to override this?

exec is a shell built-in.  Any program (here, the shell running the
script) may close stdin, stdout, and/or stderr and re-open it/them
pointing elsewhere, as many times as it wants to.  C programs might
use freopen() instead.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Måns Rullgård  
View profile  
 More options Mar 22 2012, 8:07 pm
Newsgroups: comp.unix.programmer, comp.unix.shell
From: Måns Rullgård <m...@mansr.com>
Date: Fri, 23 Mar 2012 00:07:56 +0000
Local: Thurs, Mar 22 2012 8:07 pm
Subject: Re: exec vs. nohup

gordonb.y3...@burditt.org (Gordon Burditt) writes:
>> So I have a script with the following line after the shebang:
> It would help if you'd quote the shebang.

>> exec >& file.out
>> ## some echo statements after this

>> Then I call the script with

>> nohup ./script &> /dev/null

> I don't understand the &> construct here.  Did you mean >&, and
> you're using the C shell?  If not, what shell are you using to
> invoke the script, what shell are you using to run the script, and
> what does &> mean?

He's probably using bash.  In bash, &>foo is shorthand for >foo 2>&1.

--
Måns Rullgård
m...@mansr.com


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rainer Weikusat  
View profile  
 More options Mar 22 2012, 9:39 pm
Newsgroups: comp.unix.programmer, comp.unix.shell
Followup-To: comp.unix.programmer
From: Rainer Weikusat <rweiku...@mssgmbh.com>
Date: Fri, 23 Mar 2012 01:39:12 +0000
Local: Thurs, Mar 22 2012 9:39 pm
Subject: Re: exec vs. nohup

gordonb.y3...@burditt.org (Gordon Burditt) writes:
>> So I have a script with the following line after the shebang:
> It would help if you'd quote the shebang.

>> exec >& file.out
>> ## some echo statements after this

>> Then I call the script with

>> nohup ./script &> /dev/null

> I don't understand the &> construct here.  Did you mean >&, and
> you're using the C shell?  If not, what shell are you using to
> invoke the script,

bash

> what shell are you using to run the script, and what does &> mean?

Same as >&: Redirect stdout and stderr. The manpage refers to &> as
'preferred'.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »