* Easy shell question: how to make a script killing all his childs when killed?
@ 2006-12-09 15:16 Marco Costalba
2006-12-09 17:37 ` Alex Riesen
0 siblings, 1 reply; 6+ messages in thread
From: Marco Costalba @ 2006-12-09 15:16 UTC (permalink / raw)
To: Git Mailing List
Ok. I am really bad at scripting, so perhaps my question is very silly, but...
I create and run a script with the content:
git rev-list --header --boundary --parents --topo-order 2229ff5c7c >
/tmp/qgit_135902672.txt
Then I kill the script while it's running, but his child
(git-rev-list) continues to run in background and I would like to stop
it either.
So how can I write the script to be sure that when stopped, it will
kill all his childern?
Thanks
Marco
P.S: I have no way to exec the script in fancy ways, I can just start
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Easy shell question: how to make a script killing all his childs when killed?
2006-12-09 15:16 Easy shell question: how to make a script killing all his childs when killed? Marco Costalba
@ 2006-12-09 17:37 ` Alex Riesen
2006-12-09 17:51 ` Marco Costalba
0 siblings, 1 reply; 6+ messages in thread
From: Alex Riesen @ 2006-12-09 17:37 UTC (permalink / raw)
To: Marco Costalba; +Cc: Git Mailing List
Marco Costalba, Sat, Dec 09, 2006 16:16:32 +0100:
> So how can I write the script to be sure that when stopped, it will
> kill all his childern?
Strictly speaking: you can't. Anything you'd try will either be not
portable or involve quiet complex dependencies (like perl).
Are you sure you can't control each process independently?
Speaking not so strictly, you can use a script engine which supports
either signal handling or exit notification (i.e. sh has traps and
perl has %SIG and END{}). It's unsafe, ugly and not quiet portable to
that other operating system, but it often works and is (ab)used.
> P.S: I have no way to exec the script in fancy ways, I can just start
> it and get is PID.
Which is "fancy" enough. What do you mean "start"? Starting a new
process usually and notably involves forking and execing (even if the
first thing to exec will be your shell).
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Easy shell question: how to make a script killing all his childs when killed?
2006-12-09 17:37 ` Alex Riesen
@ 2006-12-09 17:51 ` Marco Costalba
2006-12-09 21:39 ` Alex Riesen
0 siblings, 1 reply; 6+ messages in thread
From: Marco Costalba @ 2006-12-09 17:51 UTC (permalink / raw)
To: Alex Riesen; +Cc: Git Mailing List
On 12/9/06, Alex Riesen <fork0@t-online.de> wrote:
> Marco Costalba, Sat, Dec 09, 2006 16:16:32 +0100:
>
> > P.S: I have no way to exec the script in fancy ways, I can just start
> > it and get is PID.
>
> Which is "fancy" enough. What do you mean "start"? Starting a new
> process usually and notably involves forking and execing (even if the
> first thing to exec will be your shell).
>
>
By 'start' I mean it is done inside Qt QProcess class back box ;-)
Anyway I have written an homegrown 'wanna be hacker' launching script:
git rev-list --header --boundary --parents --topo-order HEAD >
/tmp/qgit_136224752.txt &
echo $!
wait
With this I can get the pid of git-rev-list from my QProcess interface
so to be able to kill it when needed with another command ('kill'
BTW).
I have googled around and it seems that 'echo $!' and 'wait' _should_
be portable among many shell, please correct me if'm wrong or if the
approach is failing (I already know it's ugly ;-) )
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Easy shell question: how to make a script killing all his childs when killed?
2006-12-09 17:51 ` Marco Costalba
@ 2006-12-09 21:39 ` Alex Riesen
2006-12-09 23:06 ` Marco Costalba
0 siblings, 1 reply; 6+ messages in thread
From: Alex Riesen @ 2006-12-09 21:39 UTC (permalink / raw)
To: Marco Costalba; +Cc: Git Mailing List
Marco Costalba, Sat, Dec 09, 2006 18:51:57 +0100:
> >> P.S: I have no way to exec the script in fancy ways, I can just start
> >> it and get is PID.
> >
> >Which is "fancy" enough. What do you mean "start"? Starting a new
> >process usually and notably involves forking and execing (even if the
> >first thing to exec will be your shell).
>
> By 'start' I mean it is done inside Qt QProcess class back box ;-)
>
> Anyway I have written an homegrown 'wanna be hacker' launching script:
>
> git rev-list --header --boundary --parents --topo-order HEAD >
> /tmp/qgit_136224752.txt &
> echo $!
> wait
>
> With this I can get the pid of git-rev-list from my QProcess interface
> so to be able to kill it when needed with another command ('kill'
> BTW).
Why do you need to save it in temporary file at all? Why don't you
read the output like gitk does? You can take a look at popen(3). It's
known to be portable among operating systems and libc's. Or, BTW, why
don't you just read qprocess.h, use processIdentifier()/pid(),
read*()-methods and the like? (though, looking at the QProcess in
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Easy shell question: how to make a script killing all his childs when killed?
2006-12-09 21:39 ` Alex Riesen
@ 2006-12-09 23:06 ` Marco Costalba
2006-12-10 14:25 ` Alex Riesen
0 siblings, 1 reply; 6+ messages in thread
From: Marco Costalba @ 2006-12-09 23:06 UTC (permalink / raw)
To: Alex Riesen; +Cc: Git Mailing List
On 12/9/06, Alex Riesen <fork0@t-online.de> wrote:
>
> Why do you need to save it in temporary file at all? Why don't you
> read the output like gitk does? You can take a look at popen(3). It's
> known to be portable among operating systems and libc's. Or, BTW, why
> don't you just read qprocess.h, use processIdentifier()/pid(),
> read*()-methods and the like? (though, looking at the QProcess in
> qt3, I wouldn't really blame you)
>
Well, I _used_ QProcess interface until last week. It's socket based
and it's quite fast (much more then gitk BTW), but due to some
internal buffering not so fast as reading from a file (in my last post
regarding git-rev-list access there are some performance numbers to
document this). It seems that socket/pipe based IPC is not as fast as
file write/read. Of course we are talking of OS cached files, no disk
access must be involved to keep the speed.
Probably someone more versed in IPC and OS internals could comment on
this, I just base my arguments on experimental testing of various IPC
systems without going deep in the reasons why the number are like
this, also because I don't have the necessary knowledge.
But the fact is that with temporary (in memory) data exchange file the
load time has been reduced by 40% against socket based QProcess
interface.
Regarding gitk we are at least one order of magnitude faster both with
QProcess and, more, with temporary files, so it's not a useful
reference in this case.
Marco
P.S: I didn't experiment with popen(). Thanks for the hint, I will
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Easy shell question: how to make a script killing all his childs when killed?
2006-12-09 23:06 ` Marco Costalba
@ 2006-12-10 14:25 ` Alex Riesen
0 siblings, 0 replies; 6+ messages in thread
From: Alex Riesen @ 2006-12-10 14:25 UTC (permalink / raw)
To: Marco Costalba; +Cc: Git Mailing List
Marco Costalba, Sun, Dec 10, 2006 00:06:34 +0100:
> On 12/9/06, Alex Riesen <fork0@t-online.de> wrote:
> >
> >Why do you need to save it in temporary file at all? Why don't you
> >read the output like gitk does? You can take a look at popen(3). It's
> >known to be portable among operating systems and libc's. Or, BTW, why
> >don't you just read qprocess.h, use processIdentifier()/pid(),
> >read*()-methods and the like? (though, looking at the QProcess in
> >qt3, I wouldn't really blame you)
> >
>
> Well, I _used_ QProcess interface until last week. It's socket based
> and it's quite fast (much more then gitk BTW), but due to some
> internal buffering not so fast as reading from a file (in my last post
> regarding git-rev-list access there are some performance numbers to
> document this). It seems that socket/pipe based IPC is not as fast as
> file write/read. Of course we are talking of OS cached files, no disk
> access must be involved to keep the speed.
Oh, I see now ("Fast access git-rev-list output...").
BTW, I just cannot reproduce that at all (on Linux):
time { git rev-list --all > /tmp/ggg; cat /tmp/ggg >/dev/null; }
tends to be somewhat slower than
time git rev-list --all | cat >/dev/null
QProcess must be doing something stupid.
> Regarding gitk we are at least one order of magnitude faster both with
> QProcess and, more, with temporary files, so it's not a useful
> reference in this case.
Dunno. It's hard to assess on "small" repos, like kernel. They feel
almost equally fast (maybe because qgit checks working directory too).
Haven't tried QGit on Windows yet (does it work there?).
> P.S: I didn't experiment with popen(). Thanks for the hint, I will
> give it a try ;-)
popen(3) usually uses pipe(2). It's also awkward with regard to
shell metacharacters and signals (as system(3) is). You can use your'
own buffers (setvbuf) so that could be a win against QProcess.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2006-12-10 14:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-09 15:16 Easy shell question: how to make a script killing all his childs when killed? Marco Costalba
2006-12-09 17:37 ` Alex Riesen
2006-12-09 17:51 ` Marco Costalba
2006-12-09 21:39 ` Alex Riesen
2006-12-09 23:06 ` Marco Costalba
2006-12-10 14:25 ` Alex Riesen
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).