Thread Prozess Starten und PID speichern: ohne open (8 answers)
Opened by bloonix at 2006-06-03 17:51

bloonix
 2006-06-04 21:46
#66985 #66985
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Hallo,

ich habe da ein kleines Problem, ich weiß nicht, wie ich am besten
eine Liste von Hashkeys durchlaufen soll. Ich habe eine Liste von
Prozess-IDs und sobald alle Prozesse nicht mehr existieren, möchte
ich aus einer while-Schleife springen.

Ich habe nun 3 Beispiele, weiß aber nicht genau, was der optimalste
Vorgang wäre. Für einen Tipp wäre ich dankbar.

Hier die Beispiele, alle ungetestet:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use strict;
use warnings;

# die Prozess-IDs habe ich jetzt mal beispielhaft angelegt
my $self = {};
$self->{23} = {};
$self->{64} = {};
$self->{745} = {};
my @pids = ();

# 1. Beispiel
@pids = keys %$self;
while (@pids) {
for my $pid (@pids) {
@pids = grep { !/^$pid$/ } @pids unless -e "/proc/$pid";
}
}

# 2. Beispiel
@pids = keys %$self;
while (@pids) {
for my $i (reverse 0..$#pids) {
splice(@pids, $i, 1) unless -e "/proc/$pids[$i]";
}
}

# 3. Beispiel
$self->{$_}->{run} = 1 for keys %$self;
my $count = keys %$self;
while ($count) {
for my $pid (sort keys %$self) {
next unless $self->{$pid}->{run};
unless (-e "/proc/$pid") {
$count--;
$self->{$pid}->{run} = 0;
}
}
}


Gruss,
opi\n\n

<!--EDIT|opi|1149443483-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Prozess Starten und PID speichern: ohne open