Suraj Kurapati
9/26/2006 6:14:00 PM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Suraj N. Kurapati wrote:
> Eero Saynatkari wrote:
>> You can parse the process list, grab the PID and issue a kill
>> on it.
>
> Here is an example. Suppose you wanted to kill all existing
> processes of the current program:
>
> pidList = `ps -C #{File.basename $0} -o pid`.split.map! {|s| s.to_i}
> pidList.shift # discard header
> pidList.reject! {|pid| pid == $$}
>
> pidList.each do |pid|
> Process.kill :SIGTERM, pid
> end
Here's a better way to write the above:
pidList = `ps -C #{File.basename $0} -o pid`.
split[1..-1]. # discard header from `ps` output
map! {|s| s.to_i}.
reject! {|pid| pid == $$}
pidList.each do |pid|
Process.kill :SIGTERM, pid
end
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
iD8DBQFFGW3JmV9O7RYnKMcRAjodAJ0aWPy7fo8ReURX4SVPpjJ8DXWanQCfd2+b
ftgHBiEredpMSOatibeylZI=
=C0wf
-----END PGP SIGNATURE-----