Re: Background processes in post-receive hook

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Apr 2, 2011 at 10:22 PM, Sitaram Chamarty <sitaramc@xxxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]