[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

get process id by using it's name.

? ??

3/24/2009 7:52:00 AM

Hi, folks.

first )
I have a question to get a process id by using it's name for all
platforms.

second)
If I want to kill some processes by it's name, are there efficient way
to do it for all platform?
For a solution for this problem, I am now using the following way ;)

ex)

lines = $x{ ps -Au${ENV['USER']} }.split("\r?\n")

lines.each do |line|
if line.match(process_name)
pids << line.strip.split[0]
end
end

count = 0
pids.each do |pid|
%x{ kill #{pid} }

count += 1 if $?.existstatus.zero?
end

print "total terminated processes : %d" % count

but, this way depends on only unix platforms.
moreover, I am not sure that all platform's output of "ps -Au" are same.

6 Answers

Heesob Park

3/24/2009 9:19:00 AM

0

Hi,

2009/3/24 Jun Young Kim <jykim@altibase.com>:
> Hi, folks.
>
> first )
> I have a question to get a process id by using it's name for all platform=
s.
>
> second)
> If I want to kill some processes by it's name, are there efficient way to=
do
> it for all platform?
> For a solution for this problem, I am now using the following way ;)
>
> ex)
>
> lines =3D $x{ ps -Au${ENV['USER']} }.split("\r?\n")
>
> lines.each do |line|
> =C2=A0 =C2=A0 =C2=A0 =C2=A0if line.match(process_name)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0pids << line.strip=
split[0]
> =C2=A0 =C2=A0 =C2=A0 =C2=A0end
> end
>
> count =3D 0
> pids.each do |pid|
> =C2=A0 =C2=A0 =C2=A0 =C2=A0%x{ kill #{pid} }
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0count +=3D 1 if $?.existstatus.zero?
> end
>
> print "total terminated processes : %d" % count
>
> but, this way depends on only unix platforms.
> moreover, I am not sure that all platform's output of "ps -Au" are same.
>
>
Try sys-proctable gem.

http://rubyforge.org/docman/view.php/610/1566/sys_proc...
http://www.ruby-forum.com/topic/139...

Regards,

Park Heesob

? ??

3/24/2009 11:50:00 AM

0

I know the sysproc library supports very good interface for this kinds =20=

of jobs.

but, sysproc doesn't support aix platforms.

$> rake test
(in /home/jykim/sys-proctable-0.8.0)
checking for rb_pid_t in ruby.h... yes
This platform not currently supported. Exiting...
.....

I need pure ruby lang based libraries or all platforms ported things :)

gamsa haeyo~

2009. 03. 24, =BF=C0=C8=C4 6:18, Heesob Park =C0=DB=BC=BA:

> Hi,
>
> 2009/3/24 Jun Young Kim <jykim@altibase.com>:
>> Hi, folks.
>>
>> first )
>> I have a question to get a process id by using it's name for all =20
>> platforms.
>>
>> second)
>> If I want to kill some processes by it's name, are there efficient =20=

>> way to do
>> it for all platform?
>> For a solution for this problem, I am now using the following way ;)
>>
>> ex)
>>
>> lines =3D $x{ ps -Au${ENV['USER']} }.split("\r?\n")
>>
>> lines.each do |line|
>> if line.match(process_name)
>> pids << line.strip.split[0]
>> end
>> end
>>
>> count =3D 0
>> pids.each do |pid|
>> %x{ kill #{pid} }
>>
>> count +=3D 1 if $?.existstatus.zero?
>> end
>>
>> print "total terminated processes : %d" % count
>>
>> but, this way depends on only unix platforms.
>> moreover, I am not sure that all platform's output of "ps -Au" are =20=

>> same.
>>
>>
> Try sys-proctable gem.
>
> http://rubyforge.org/docman/view.php/610/1566/sys_proc...
> http://www.ruby-forum.com/topic/139...
>
> Regards,
>
> Park Heesob
>
>


***************************
DSLab, CQ =B1=E8=C1=D8=BF=B5 =B5=E5=B8=B2
(02-2082-1091)
***************************






Eric Hodel

3/24/2009 6:38:00 PM

0

On Mar 24, 2009, at 04:50, Jun Young Kim wrote:

> I know the sysproc library supports very good interface for this
> kinds of jobs.
>
> but, sysproc doesn't support aix platforms.
>
> $> rake test
> (in /home/jykim/sys-proctable-0.8.0)
> checking for rb_pid_t in ruby.h... yes
> This platform not currently supported. Exiting...
> .....
>
> I need pure ruby lang based libraries or all platforms ported
> things :)

Since you seem to have access to an aix machine, I'm pretty sure it'll
be easy to add aix support. I doubt the calls needed are much
different than the other unix-based machines.

? ??

3/25/2009 6:06:00 AM

0

yes, I also believe that is the best option for me :)

anyway, thanks for all.

2009. 03. 25, =BF=C0=C0=FC 3:37, Eric Hodel =C0=DB=BC=BA:

> On Mar 24, 2009, at 04:50, Jun Young Kim wrote:
>
>> I know the sysproc library supports very good interface for this =20
>> kinds of jobs.
>>
>> but, sysproc doesn't support aix platforms.
>>
>> $> rake test
>> (in /home/jykim/sys-proctable-0.8.0)
>> checking for rb_pid_t in ruby.h... yes
>> This platform not currently supported. Exiting...
>> .....
>>
>> I need pure ruby lang based libraries or all platforms ported =20
>> things :)
>
> Since you seem to have access to an aix machine, I'm pretty sure =20
> it'll be easy to add aix support. I doubt the calls needed are much =20=

> different than the other unix-based machines.
>
>


***************************
DSLab, CQ =B1=E8=C1=D8=BF=B5 =B5=E5=B8=B2
(02-2082-1091)
***************************






Daniel Berger

3/25/2009 12:13:00 PM

0

Jun Young Kim wrote:
> yes, I also believe that is the best option for me :)
>
> anyway, thanks for all.
>
> 2009. 03. 25, ¿AAu 3:37, Eric Hodel AU¼º:
>
>> On Mar 24, 2009, at 04:50, Jun Young Kim wrote:
>>
>>> I know the sysproc library supports very good interface for this
>>> kinds of jobs.
>>>
>>> but, sysproc doesn't support aix platforms.

<snip>

I don't have access to an AIX machine, but this might get you started on
a port for sys-proctable:

http://cpansearch.perl.org/src/DURIST/Proc-ProcessTabl...

There appear to be 2 variants for AIX, so I'm not sure which one Dan is
using, but perhaps they'll give you some ideas.

Regards,

Dan

RichL

1/7/2014 4:25:00 AM

0

"DianeE" <TiredOfSpam@SorryFolks.com> wrote in message
news:Ku-dnUayb_KBxlbPnZ2dnUVZ_q6dnZ2d@giganews.com...
> You may be interested to hear the original version, by--of all
> people!--Jerry Lee Lewis:
>
> http://www.youtube.com/watch?v=u...
>
> The song was written by Mickey Newbury.

Much better!