git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Ratterman <jratt0@gmail.com>
To: Sitaram Chamarty <sitaramc@gmail.com>
Cc: James Pickens <jepicken@gmail.com>, Git list <git@vger.kernel.org>
Subject: Re: Background processes in post-receive hook
Date: Sat, 2 Apr 2011 23:59:59 -0500	[thread overview]
Message-ID: <AANLkTim3Eu+rHc3_7_PWsALK3QwuzyX2Anbn8o6aCbAE@mail.gmail.com> (raw)
In-Reply-To: <BANLkTin4-fMhi_5H1oZ+gPB99stj5GRjVA@mail.gmail.com>

On Sat, Apr 2, 2011 at 10:22 PM, Sitaram Chamarty <sitaramc@gmail.com> wrote:
> interestingly, the double fork trick doesn't work either...
>
>  ( ( long-running-command & ) )

I think that is because the hook is still reading from the command's
stdout.  If you close stdout/stderr, I would expect it to work.  For
example, the "sort" command below cannot exit until all sub-programs
have finished feeding it data.  You can see that despite the levels of
forking involved, the stdout of perl and the stdin of sort are the
same.

$ ( ( perl -e 'sleep 60; print "THERE\n";' & ) ) | sort > /tmp/out &
[1] 4033
$ ps h
...
 4033 pts/10   S      0:00 sort
 4035 pts/10   S      0:00 perl -e sleep 60; print "THERE\n";
...
$ ll /proc/{4035,4033}/fd
/proc/4033/fd:
total 0
lr-x------ 1 jratt bgq 64 Apr  2 23:49 0 -> pipe:[55227211]
l-wx------ 1 jratt bgq 64 Apr  2 23:49 1 -> /tmp/out
lrwx------ 1 jratt bgq 64 Apr  2 23:49 2 -> /dev/pts/10

/proc/4035/fd:
total 0
lr-x------ 1 jratt bgq 64 Apr  2 23:49 0 -> /dev/null
l-wx------ 1 jratt bgq 64 Apr  2 23:49 1 -> pipe:[55227211]
lrwx------ 1 jratt bgq 64 Apr  2 23:49 2 -> /dev/pts/10
$ cat /tmp/out
$ fg
( ( perl -e 'sleep 60; print "THERE\n";' & ) ) | sort > /tmp/out
$ cat /tmp/out
THERE



However, this version exits before the shell returns to the prompt
(and the output is lost).

$ ( ( perl -e 'close STDOUT; close STDERR;sleep 60; print "THERE\n";'
& ) ) | sort > /tmp/out &
[1] 4097
[1]+  Done                    ( ( perl -e 'close STDOUT; close
STDERR;sleep 60; print "THERE\n";' & ) ) | sort > /tmp/out
$



Joe

  reply	other threads:[~2011-04-03  5:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-02 23:03 Background processes in post-receive hook James Pickens
2011-04-03  0:35 ` Junio C Hamano
2011-04-03  3:22 ` Sitaram Chamarty
2011-04-03  4:59   ` Joe Ratterman [this message]
2011-04-03  5:06   ` Jonathan Nieder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTim3Eu+rHc3_7_PWsALK3QwuzyX2Anbn8o6aCbAE@mail.gmail.com \
    --to=jratt0@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jepicken@gmail.com \
    --cc=sitaramc@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).