comparing PIDs in shell
am 19.12.2007 16:11:48 von marconi
Hi,
There is a file having a list of running PIDs and another file having
a list of registered PIDs. How can we check if the number of running
PIDs are less or more than the registered PIDs, comparing the total
no. in each and also the values.
Request you to pls give your inputs.
Thanks a lot in advance.
Re: comparing PIDs in shell
am 19.12.2007 16:20:40 von Joachim Schmitz
"marconi" schrieb im Newsbeitrag
news:d291c279-635c-4992-8670-ed8997ac0d58@y5g2000hsf.googleg roups.com...
> Hi,
>
> There is a file having a list of running PIDs and another file having
> a list of registered PIDs. How can we check if the number of running
> PIDs are less or more than the registered PIDs, comparing the total
> no. in each and also the values.
>
> Request you to pls give your inputs.
if [ ${a:=$(wc -l file1)} -lt ${b:=$(wc -l file2)} ]
then
echo less lines in file1 than in file2
elif [ $a -gt $b ]
then
echo more lines in file1 than in file2
else
echo same number of lines in both files
fi
Bye, Jojo
Re: comparing PIDs in shell
am 19.12.2007 16:24:11 von Ed Morton
On 12/19/2007 9:11 AM, marconi wrote:
> Hi,
>
> There is a file having a list of running PIDs and another file having
> a list of registered PIDs. How can we check if the number of running
> PIDs are less or more than the registered PIDs, comparing the total
> no. in each and also the values.
>
> Request you to pls give your inputs.
>
> Thanks a lot in advance.
>
You should be able to tweak this to your needs, untested (check the case/spelling!):
awk 'NR==FNR{ reg[$0]; nReg++; next }
$0 in reg { regRun[$0]; nRegRun++; next }
{ unregRun[$0]; nUnregRun++ }
END { for (pid in reg) {
if ( (pid in regRun) || (pid in unregRun) ) {
unrunReg[pid]
nUnrunReg++
}
printf "Registered (%d):\n", nReg
for (pid in reg) print pid
printf "Registered and running (%d):\n", nRegRun
for (pid in regRun) print pid
printf "Registered but not running (%d):\n, nUnrunReg
for (pid in unregRun) print pid
printf "Running but not registered (%d):\n", nUnregRun
for (pid in unregRun) print pid
}' registered running
Regards,
Ed.
Re: comparing PIDs in shell
am 19.12.2007 16:25:21 von Janis Papanagnou
On 19 Dez., 16:11, marconi wrote:
> Hi,
>
> There is a file having a list of running PIDs and another file having
> a list of registered PIDs. How can we check if the number of running
> PIDs are less or more than the registered PIDs, comparing the total
> no. in each and also the values.
awk '
NR==FNR { regPID[$1]; reg++; next }
{ run++ }
$1 in regPID { reg_and_run++ }
END { print run, reg, reg_and_run
if (reg < run) print "less registered"
if (reg > run) print "less running"
# etc.
}
' file_with_registeredPIDs file_with_runningPIDs
Janis
>
> Request you to pls give your inputs.
>
> Thanks a lot in advance.
Re: comparing PIDs in shell
am 19.12.2007 16:37:39 von Janis Papanagnou
On 19 Dez., 16:20, "Joachim Schmitz"
wrote:
> "marconi" schrieb im Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58@y5g2000 hsf.googlegroups.com...
>
> > Hi,
>
> > There is a file having a list of running PIDs and another file having
> > a list of registered PIDs. How can we check if the number of running
> > PIDs are less or more than the registered PIDs, comparing the total
> > no. in each and also the values.
>
> > Request you to pls give your inputs.
>
> if [ ${a:=$(wc -l file1)} -lt ${b:=$(wc -l file2)} ]
In what shell does that work?
Mind that wc -l file produces other output than wc -l
> then
> echo less lines in file1 than in file2
> elif [ $a -gt $b ]
> then
> echo more lines in file1 than in file2
> else
> echo same number of lines in both files
> fi
Your program does not consider the actual PID values in the sets,
rather only the number of lines (resp. number of PIDs).
Janis
> Bye, Jojo
Re: comparing PIDs in shell
am 19.12.2007 16:46:26 von Joachim Schmitz
"Janis" schrieb im Newsbeitrag
news:6a66f512-2862-4c02-8866-77e97fd8071f@s12g2000prg.google groups.com...
> On 19 Dez., 16:20, "Joachim Schmitz"
> wrote:
>> "marconi" schrieb im
>> Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58@y5g2000 hsf.googlegroups.com...
>>
>> > Hi,
>>
>> > There is a file having a list of running PIDs and another file having
>> > a list of registered PIDs. How can we check if the number of running
>> > PIDs are less or more than the registered PIDs, comparing the total
>> > no. in each and also the values.
>>
>> > Request you to pls give your inputs.
>>
>> if [ ${a:=$(wc -l file1)} -lt ${b:=$(wc -l file2)} ]
>
> In what shell does that work?
ksh, bash
> Mind that wc -l file produces other output than wc -l
ops, true, so let's use wc -l
>> then
>> echo less lines in file1 than in file2
>> elif [ $a -gt $b ]
>> then
>> echo more lines in file1 than in file2
>> else
>> echo same number of lines in both files
>> fi
>
> Your program does not consider the actual PID values in the sets,
> rather only the number of lines (resp. number of PIDs).
That was his 1st objective. I missed the 2nd.
Bye, Jojo
Re: comparing PIDs in shell
am 19.12.2007 17:07:28 von Janis Papanagnou
On 19 Dez., 16:46, "Joachim Schmitz"
wrote:
> "Janis" schrieb im Newsbeitragnews:6a66f512-2862-4c02-8866-77e97fd8071f@s12g200 0prg.googlegroups.com...
>
> > On 19 Dez., 16:20, "Joachim Schmitz"
> > wrote:
> >> "marconi" schrieb im
> >> Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58@y5g2000 hsf.googlegroups.com...
>
> >> > Hi,
>
> >> > There is a file having a list of running PIDs and another file having
> >> > a list of registered PIDs. How can we check if the number of running
> >> > PIDs are less or more than the registered PIDs, comparing the total
> >> > no. in each and also the values.
>
> >> > Request you to pls give your inputs.
>
> >> if [ ${a:=$(wc -l file1)} -lt ${b:=$(wc -l file2)} ]
>
> > In what shell does that work?
>
> ksh, bash
Not in the ksh I am currently using, neither in my bash.
> > Mind that wc -l file produces other output than wc -l
>
> ops, true, so let's use wc -l
But it doesn't seem to fix your construct either.
At least on WinDOS (MKS ksh, Cygwin bash) it produces errors.
Janis
Re: comparing PIDs in shell
am 19.12.2007 17:41:10 von Joachim Schmitz
"Janis" schrieb im Newsbeitrag
news:9d1502ef-2c20-4a4f-adcf-5af87c01e1db@r60g2000hsc.google groups.com...
> On 19 Dez., 16:46, "Joachim Schmitz"
> wrote:
>> "Janis" schrieb im
>> Newsbeitragnews:6a66f512-2862-4c02-8866-77e97fd8071f@s12g200 0prg.googlegroups.com...
>>
>> > On 19 Dez., 16:20, "Joachim Schmitz"
>> > wrote:
>> >> "marconi" schrieb im
>> >> Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58@y5g2000 hsf.googlegroups.com...
>>
>> >> > Hi,
>>
>> >> > There is a file having a list of running PIDs and another file
>> >> > having
>> >> > a list of registered PIDs. How can we check if the number of running
>> >> > PIDs are less or more than the registered PIDs, comparing the total
>> >> > no. in each and also the values.
>>
>> >> > Request you to pls give your inputs.
>>
>> >> if [ ${a:=$(wc -l file1)} -lt ${b:=$(wc -l file2)} ]
>>
>> > In what shell does that work?
>>
>> ksh, bash
>
> Not in the ksh I am currently using, neither in my bash.
>
>> > Mind that wc -l file produces other output than wc -l
>>
>> ops, true, so let's use wc -l
>
> But it doesn't seem to fix your construct either.
> At least on WinDOS (MKS ksh, Cygwin bash) it produces errors.
Works fine here, with the wc -l
might fail is a or b are set so do an unset a b first
Bye, Jojo
Re: comparing PIDs in shell
am 19.12.2007 18:14:31 von Janis Papanagnou
Joachim Schmitz wrote:
> "Janis" schrieb im Newsbeitrag
> news:9d1502ef-2c20-4a4f-adcf-5af87c01e1db@r60g2000hsc.google groups.com...
>
>>On 19 Dez., 16:46, "Joachim Schmitz"
>>wrote:
>>
>>>"Janis" schrieb im
>>>Newsbeitragnews:6a66f512-2862-4c02-8866-77e97fd8071f@s12g 2000prg.googlegroups.com...
>>>
>>>
>>>>On 19 Dez., 16:20, "Joachim Schmitz"
>>>>wrote:
>>>>
>>>>>"marconi" schrieb im
>>>>>Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58@y5 g2000hsf.googlegroups.com...
>>>
>>>>>>Hi,
>>>
>>>>>>There is a file having a list of running PIDs and another file
>>>>>>having
>>>>>>a list of registered PIDs. How can we check if the number of running
>>>>>>PIDs are less or more than the registered PIDs, comparing the total
>>>>>>no. in each and also the values.
>>>
>>>>>>Request you to pls give your inputs.
>>>
>>>>>if [ ${a:=$(wc -l file1)} -lt ${b:=$(wc -l file2)} ]
>>>
>>>>In what shell does that work?
>>>
>>>ksh, bash
>>
>>Not in the ksh I am currently using, neither in my bash.
>>
>>
>>>>Mind that wc -l file produces other output than wc -l
>>>
>>>ops, true, so let's use wc -l
>>
>>But it doesn't seem to fix your construct either.
>>At least on WinDOS (MKS ksh, Cygwin bash) it produces errors.
>
> Works fine here, with the wc -l
> might fail is a or b are set so do an unset a b first
No, that's not the reason. Because the construct you proposed is unsafe
in that respect I already did the variable initialization anyway.
Curiously I had played a bit around with that code and it seemed to me
it might be the effect of some spurious '\r'. Other less conservative
constructs like [[...]] and ((...)) don't seem to show that problem.
But I haven't spent too much time to try to fix or examine that further.
Janis
>
> Bye, Jojo
>
>