[Viana-pm] selective KILLing...
Luis Azevedo
braceta at sapo.pt
Fri Oct 26 10:18:56 PDT 2007
Boas João,
Antes de mais vê se reparas mas é esse teclado :PPPPP
1) Em linux, o PID é um contador de 16 bit sempre incremental, i.e., quando
chega o limite, recomeça a contagem sem colidir com PID's atribuídos nesse
mesmo instante. Acho muito improvável que aconteçam colisões, mas podes fazer
um script para criar processos e "dar a volta" ao contador até chegar o PID o
teu child. Depois verificas se o kill é feito ao teu $child.
2) Devias usar a função "kill" em vez do system("kill...), see: perldoc -f
kill
If SIGNAL is zero, no signal is sent to the process. This is a useful way
to check that a child process is alive and hasn’t changed its UID.
Podes sempre verificar se o filho não morreu com o kill e a seguir matar!
Killing spree :)
Hope it helps, abraço.
Luís Azevedo
P.S: Ainda me estou a rir do que te aconteceu ao teclado :PP Podias usar um
USB, não? :P
On Friday 26 October 2007, Joao Miguel Ferreira wrote:
> Olá a todos,
>
> (oi meui tecladoi está a escrever 'i's quiandoii carregoi em 'o' e 'u's,
> descuilpem.....)
>
>
> p.f. reparem neste código:
>
> --------------------------------------
> sub something_timed_out {die "GOT TIRED OF WAITING";};
> $SIG{ALRM} = \&something_timed_out;
> --------------------------------------
> $rv='Ok';
> eval
> {
> $child=fork;
> if (defined($child)) {
> if ($child) {
> alarm(10);
> wait;
> alarm(0);
> $rv='child didnt take more than 10 secs';
> } else {
> do_some_very_slow_stuff;
> exit 1;
> };
> } else {
> $rv="Cannot cannot fork";
> };
> };
>
> if ($@)
> {
> if ($@ =~ /GOT TIRED OF WAITING/)
> {
> system("kill -TERM $child");
> $rv="child did take long so I TERMed it";
> };
> $rv="error !?!";
> };
>
> return $rv;
> --------------------------------------
>
> proiblema: isto é para coiirrer em root !!!!!!!!!
>
> tenhoi receio de, noi kill, em vez de matar o meu child, matar uim
> oiuitroi quialquier que entretantoi tenha apanhadoi aquiele PID.
>
> Ou o SO coinsegue gerir os PIDs poir foirma a não atribuiir este antes
> doii pai terminar ????
>
> há coimentários ?
>
>
>
>
> thx++;
> return 0;
> };
>
> Joao Ferreira
>
>
>
> _______________________________________________
> Viana-pm mailing list
> Viana-pm at pm.org
> http://mail.pm.org/mailman/listinfo/viana-pm
--
Luis Azevedo
braceta at sapo.pt
More information about the Viana-pm
mailing list