[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Process id

Gianni Dupro

6/16/2007 4:14:00 PM

Hi everybody I m nobie of ruby

I need some hint about to catch a id of a certain process

for instance if I run this line of code

`ruby file.rb` there is a possibility to have the id of this process
(file.rb process)

my problem if the file.rb was lock I need the pId for kill it


Thanks to all

Best Regards

joksy

--
Posted via http://www.ruby-....

3 Answers

byronsalty

6/16/2007 4:51:00 PM

0

On Jun 16, 12:13 pm, Gianni Dupro <tetta...@lu.unisi.ch> wrote:
> Hi everybody I m nobie of ruby
>
> I need some hint about to catch a id of a certain process
>
> for instance if I run this line of code
>
> `ruby file.rb` there is a possibility to have the id of this process
> (file.rb process)
>
> my problem if the file.rb was lock I need the pId for kill it

You can see the process id by putting this as the first line:
print "#{Process.pid}\n"

Alternatively you seem to be using a *nix computer so you can find the
process with ps:
ps -ef | grep ruby

- Byron
-----
http://www.salt...

james.d.masters

6/16/2007 5:49:00 PM

0

On Jun 16, 9:13 am, Gianni Dupro <tetta...@lu.unisi.ch> wrote:
> Hi everybody I m nobie of ruby
>
> I need some hint about to catch a id of a certain process
>
> for instance if I run this line of code
>
> `ruby file.rb` there is a possibility to have the id of this process
> (file.rb process)
>
> my problem if the file.rb was lock I need the pId for kill it
>
> Thanks to all
>
> Best Regards
>
> joksy
>
> --
> Posted viahttp:/.......

A quick look at Kernel#` in the Ruby documentation (http:/...
doc.org/core/) mentions a special (Perl-esque) variable $? which can
be used after calling a system command with ``:

bash-2.05a$ irb.bat
irb(main):001:0> `echo "hi"`
=> "\"hi\"\n"
irb(main):002:0> $?.pid
=> 3124

And as you can see that variable happens to have a #pid method. Does
anyone know if there is a better way without using the esoteric $?
variable?

-James

Gianni Dupro

6/17/2007 7:24:00 PM

0

byronsalty wrote:
> On Jun 16, 12:13 pm, Gianni Dupro <tetta...@lu.unisi.ch> wrote:
>> Hi everybody I m nobie of ruby
>>
>> I need some hint about to catch a id of a certain process
>>
>> for instance if I run this line of code
>>
>> `ruby file.rb` there is a possibility to have the id of this process
>> (file.rb process)
>>
>> my problem if the file.rb was lock I need the pId for kill it
>
> You can see the process id by putting this as the first line:
> print "#{Process.pid}\n"
>
> Alternatively you seem to be using a *nix computer so you can find the
> process with ps:
> ps -ef | grep ruby
>
> - Byron

Thanks a lot for the help to use some unix command like ps.

I do something easier

exec("ruby a.rb | ps 1>logFile")

and next grep the file for a ruby process.

And now born another problem if

I running directly with ruby like name$ ruby file.rb and in the file I
have the information but move it into a rails files doesn t work.

Any suggest??

thanks to all have a nice day


Joksy

--
Posted via http://www.ruby-....