* Background processes in post-receive hook
@ 2011-04-02 23:03 James Pickens
2011-04-03 0:35 ` Junio C Hamano
2011-04-03 3:22 ` Sitaram Chamarty
0 siblings, 2 replies; 5+ messages in thread
From: James Pickens @ 2011-04-02 23:03 UTC (permalink / raw)
To: Git ML
Hi,
I have a post-receive hook (bash script) that launches several background
processes and exits immediately. I do that so I don't have to wait for the
background processes to finish every time I push to the repository, but Git
seems to wait for them to finish anyways, even though the post-receive hook
itself already exited. Is there any way to stop Git from waiting and let the
push finish immediately? Sorry if I'm missing something obvious...
Thanks,
James
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Background processes in post-receive hook
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
1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2011-04-03 0:35 UTC (permalink / raw)
To: James Pickens; +Cc: Git ML
James Pickens <jepicken@gmail.com> writes:
> I have a post-receive hook (bash script) that launches several background
> processes and exits immediately. I do that so I don't have to wait for the
> background processes to finish every time I push to the repository, but Git
> seems to wait for them to finish anyways, even though the post-receive hook
> itself already exited. Is there any way to stop Git from waiting and let the
> push finish immediately?
An easy way to do that is to run whatever lengthy process you do not want
to wait for using
echo "that command" | at now
in the hook ;-).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Background processes in post-receive hook
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
2011-04-03 5:06 ` Jonathan Nieder
1 sibling, 2 replies; 5+ messages in thread
From: Sitaram Chamarty @ 2011-04-03 3:22 UTC (permalink / raw)
To: James Pickens; +Cc: Git ML
On Sun, Apr 3, 2011 at 4:33 AM, James Pickens <jepicken@gmail.com> wrote:
> Hi,
>
> I have a post-receive hook (bash script) that launches several background
> processes and exits immediately. I do that so I don't have to wait for the
> background processes to finish every time I push to the repository, but Git
> seems to wait for them to finish anyways, even though the post-receive hook
> itself already exited. Is there any way to stop Git from waiting and let the
> push finish immediately? Sorry if I'm missing something obvious...
interestingly, the double fork trick doesn't work either...
( ( long-running-command & ) )
What Junio said may be the only alternative...
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Background processes in post-receive hook
2011-04-03 3:22 ` Sitaram Chamarty
@ 2011-04-03 4:59 ` Joe Ratterman
2011-04-03 5:06 ` Jonathan Nieder
1 sibling, 0 replies; 5+ messages in thread
From: Joe Ratterman @ 2011-04-03 4:59 UTC (permalink / raw)
To: Sitaram Chamarty; +Cc: James Pickens, Git list
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Background processes in post-receive hook
2011-04-03 3:22 ` Sitaram Chamarty
2011-04-03 4:59 ` Joe Ratterman
@ 2011-04-03 5:06 ` Jonathan Nieder
1 sibling, 0 replies; 5+ messages in thread
From: Jonathan Nieder @ 2011-04-03 5:06 UTC (permalink / raw)
To: Sitaram Chamarty; +Cc: James Pickens, Git ML
Sitaram Chamarty wrote:
> interestingly, the double fork trick doesn't work either...
>
> ( ( long-running-command & ) )
Hopefully closing the output pipe does the trick.
exec long-running-command >&- 2>&- &
Thanks for an interesting example.
Jonathan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-04-03 5:08 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2011-04-03 5:06 ` Jonathan Nieder
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).