Re: get process id by using it's name.



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 작성:

Hi,

2009/3/24 Jun Young Kim <jykim@xxxxxxxxxxxx>:
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.


Try sys-proctable gem.

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

Regards,

Park Heesob




***************************
DSLab, CQ 김준영 드림
(02-2082-1091)
***************************






.



Relevant Pages

  • get process id by using its name.
    ... If I want to kill some processes by it's name, ... %x{kill #{pid}} ... this way depends on only unix platforms. ...
    (comp.lang.ruby)
  • Re: Why are process IDs always even?
    ... We'd be much interested in the design reason for it ... > Obviously AIX doens't use the lowest bit for PID. ... Under Linux, FreeBSD, and Solaris (most of the major platforms that we ... it's not a problem re: AIX pid scheme -- it's just a simple ...
    (comp.unix.aix)
  • Re: Turn off ZeroDivisionError?
    ... platforms do exactly what I want for division by zero: ... Python doesn't generate exceptions for other floating point ... case of division by zero. ...
    (comp.lang.python)
  • [PATCH] powerpc: Change _tlbie arguments to reflect new API
    ... A new pid argument has been added to _tlbie for 4xx platforms. ... Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)
  • Re: [PATCH] APIC: Remove unused variable
    ... This is left over from commit 7b20bd5fb9 "x86, irq: Kill ... GSI override for ES7000 platforms. ...
    (Linux-Kernel)