Forum: Ruby get process id by using it's name.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7caba80fca2ac4ddbb7f55957e5c0dec?d=identicon&s=25 Jun Young Kim (Guest)
on 2009-03-24 08:55
(Received via mailing list)
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.
666b4e17b4bb0e2d999037a25f65a7cb?d=identicon&s=25 Heesob Park (phasis)
on 2009-03-24 10:22
(Received via mailing list)
Hi,

2009/3/24 Jun Young Kim <jykim@altibase.com>:
> ex)
> pids.each do |pid|
>
Try sys-proctable gem.

http://rubyforge.org/docman/view.php/610/1566/sys_...
http://www.ruby-forum.com/topic/139227#618978

Regards,

Park Heesob
7caba80fca2ac4ddbb7f55957e5c0dec?d=identicon&s=25 Jun Young Kim (Guest)
on 2009-03-24 12:54
(Received via mailing list)
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 :)

gamsa haeyo~

2009. 03. 24, ¿ÀÈÄ 6:18, Heesob Park ÀÛ¼º:

>> If I want to kill some processes by it's name, are there efficient
>>                pids << line.strip.split[0]
>> print "total terminated processes : %d" % count
>
> Regards,
>
> Park Heesob
>
>


***************************
    DSLab, CQ ±èÁØ¿µ µå¸²
              (02-2082-1091)
***************************
58479f76374a3ba3c69b9804163f39f4?d=identicon&s=25 Eric Hodel (Guest)
on 2009-03-24 19:42
(Received via mailing list)
On Mar 24, 2009, at 04:50, Jun Young Kim wrote:

>
> 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.
7caba80fca2ac4ddbb7f55957e5c0dec?d=identicon&s=25 Jun Young Kim (Guest)
on 2009-03-25 07:10
(Received via mailing list)
yes, I also believe that is the best option for me :)

anyway, thanks for all.

2009. 03. 25, ¿ÀÀü 3:37, Eric Hodel ÀÛ¼º:

>> 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.
>
>


***************************
    DSLab, CQ ±èÁØ¿µ µå¸²
              (02-2082-1091)
***************************
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (djberg96)
on 2009-03-25 13:16
(Received via mailing list)
Jun Young Kim wrote:
>>>
>>> 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-Process...

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
This topic is locked and can not be replied to.