git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Background processes in post-receive hook

From
Joe Ratterman <jratt0@gmail.com>
Date
Apr 3, 2011, 04:59 UTC
Message-ID
<AANLkTim3Eu+rHc3_7_PWsALK3QwuzyX2Anbn8o6aCbAE@mail.gmail.com>
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
Previous: Sitaram ChamartyNext: Jonathan Nieder
Message 4 of 5 in “Background processes in post-receive hook”
  1. James PickensApr 2, 2011
  2. Junio C HamanoApr 3, 2011
  3. Sitaram ChamartyApr 3, 2011
  4. Joe RattermanApr 3, 2011
  5. Jonathan NiederApr 3, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.