comparing PIDs in shell

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.
marconi [ Mi, 19 Dezember 2007 16:11 ] [ ID #1889976 ]

Re: comparing PIDs in shell

"marconi" <kirankumar.techy [at] gmail.com> schrieb im Newsbeitrag
news:d291c279-635c-4992-8670-ed8997ac0d58 [at] 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
Joachim Schmitz [ Mi, 19 Dezember 2007 16:20 ] [ ID #1889977 ]

Re: comparing PIDs in shell

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.
Ed Morton [ Mi, 19 Dezember 2007 16:24 ] [ ID #1889978 ]

Re: comparing PIDs in shell

On 19 Dez., 16:11, marconi <kirankumar.te... [at] gmail.com> 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.
Janis Papanagnou [ Mi, 19 Dezember 2007 16:25 ] [ ID #1889979 ]

Re: comparing PIDs in shell

On 19 Dez., 16:20, "Joachim Schmitz" <nospam.j... [at] schmitz-digital.de>
wrote:
> "marconi" <kirankumar.te... [at] gmail.com> schrieb im Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58 [at] 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 <file

> 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
Janis Papanagnou [ Mi, 19 Dezember 2007 16:37 ] [ ID #1889981 ]

Re: comparing PIDs in shell

"Janis" <janis_papanagnou [at] hotmail.com> schrieb im Newsbeitrag
news:6a66f512-2862-4c02-8866-77e97fd8071f [at] s12g2000prg.google groups.com...
> On 19 Dez., 16:20, "Joachim Schmitz" <nospam.j... [at] schmitz-digital.de>
> wrote:
>> "marconi" <kirankumar.te... [at] gmail.com> schrieb im
>> Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58 [at] 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 <file
ops, true, so let's use wc -l <file then

>> 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
Joachim Schmitz [ Mi, 19 Dezember 2007 16:46 ] [ ID #1889982 ]

Re: comparing PIDs in shell

On 19 Dez., 16:46, "Joachim Schmitz" <nospam.j... [at] schmitz-digital.de>
wrote:
> "Janis" <janis_papanag... [at] hotmail.com> schrieb im Newsbeitragnews:6a66f512-2862-4c02-8866-77e97fd8071f [at] s12g200 0prg.googlegroups.com...
>
> > On 19 Dez., 16:20, "Joachim Schmitz" <nospam.j... [at] schmitz-digital.de>
> > wrote:
> >> "marconi" <kirankumar.te... [at] gmail.com> schrieb im
> >> Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58 [at] 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 <file
>
> ops, true, so let's use wc -l <file then

But it doesn't seem to fix your construct either.
At least on WinDOS (MKS ksh, Cygwin bash) it produces errors.

Janis
Janis Papanagnou [ Mi, 19 Dezember 2007 17:07 ] [ ID #1889983 ]

Re: comparing PIDs in shell

"Janis" <janis_papanagnou [at] hotmail.com> schrieb im Newsbeitrag
news:9d1502ef-2c20-4a4f-adcf-5af87c01e1db [at] r60g2000hsc.google groups.com...
> On 19 Dez., 16:46, "Joachim Schmitz" <nospam.j... [at] schmitz-digital.de>
> wrote:
>> "Janis" <janis_papanag... [at] hotmail.com> schrieb im
>> Newsbeitragnews:6a66f512-2862-4c02-8866-77e97fd8071f [at] s12g200 0prg.googlegroups.com...
>>
>> > On 19 Dez., 16:20, "Joachim Schmitz" <nospam.j... [at] schmitz-digital.de>
>> > wrote:
>> >> "marconi" <kirankumar.te... [at] gmail.com> schrieb im
>> >> Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58 [at] 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 <file
>>
>> ops, true, so let's use wc -l <file then
>
> 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 <file.
might fail is a or b are set so do an unset a b first

Bye, Jojo
Joachim Schmitz [ Mi, 19 Dezember 2007 17:41 ] [ ID #1889985 ]

Re: comparing PIDs in shell

Joachim Schmitz wrote:
> "Janis" <janis_papanagnou [at] hotmail.com> schrieb im Newsbeitrag
> news:9d1502ef-2c20-4a4f-adcf-5af87c01e1db [at] r60g2000hsc.google groups.com...
>
>>On 19 Dez., 16:46, "Joachim Schmitz" <nospam.j... [at] schmitz-digital.de>
>>wrote:
>>
>>>"Janis" <janis_papanag... [at] hotmail.com> schrieb im
>>>Newsbeitragnews:6a66f512-2862-4c02-8866-77e97fd8071f [at] s12g 2000prg.googlegroups.com...
>>>
>>>
>>>>On 19 Dez., 16:20, "Joachim Schmitz" <nospam.j... [at] schmitz-digital.de>
>>>>wrote:
>>>>
>>>>>"marconi" <kirankumar.te... [at] gmail.com> schrieb im
>>>>>Newsbeitragnews:d291c279-635c-4992-8670-ed8997ac0d58 [at] 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 <file
>>>
>>>ops, true, so let's use wc -l <file then
>>
>>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 <file.
> 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
>
>
Janis Papanagnou [ Mi, 19 Dezember 2007 18:14 ] [ ID #1889987 ]
Linux » comp.unix.shell » comparing PIDs in shell

Vorheriges Thema: Req: SQL Developer / DBA
Nächstes Thema: To find a filename in all paths and directories..