# Process Leak after using Session module

**URL:** <https://www.ruby-forum.com/t/process-leak-after-using-session-module/168976>\
**Category:** Ruby\
**Created:** [May 28, 2009, 12:37am UTC](https://www.ruby-forum.com/t/process-leak-after-using-session-module/168976 "2009-05-28T00:37:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pbhandar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/76d3ee/32.png) [@pbhandar](https://www.ruby-forum.com/u/pbhandar)\
**Post date:** [May 28, 2009, 12:37am UTC](https://www.ruby-forum.com/t/process-leak-after-using-session-module/168976/1 "2009-05-28T00:37:37Z")

</div>

Hi,

This script has a process leak with a bash session being left open every  
time I run it. I can’t find a way to close the bash object after I am  
done. Docs don’t explicitly don’t cover this… or I am missing something  
simple. Can anyone shed some light on this or point to docs that I may  
not be aware of? I looked at the readme provided by Sessions module  
authors so far.

Thanks in advance.

Prakash

bash = Session::Shell.new

oratab\_file = Oratab()  
ofile = File.open(oratab\_file, “r”)  
############################################################

# Looping through all lines

############################################################  
bash.execute “\>instancestatus-output.txt”  
ofile.each { |oratab\_line|  
if oratab\_line =~ /^\s+/  
else  
if oratab\_line =~ /^#/  
else  
if oratab\_line =~ /^+/  
else  
db\_str = db\_and\_flag(oratab\_line)  
db\_arr = db\_str.split(",")  
db\_name = db\_arr[0]  
puts db\_name

```
       #########################################################
       # Make calls to the right database calls right here
       ##########################################################
       bash.execute "echo #{db_name}:>>instancestatus-output.txt"
       bash.execute "InstanceStatus.sh #{db_name}", 1 => STDOUT, 2

```

=\> STDERR do |out,err|  
puts out if out  
puts err if err  
end  
##########################################################  
# End of loop for bash.execute  
##########################################################  
end  
end  
end

# /\* end of the ofile.each statement \*/

#################################################################

# 

# 

#################################################################  
}  
end

---

<div class="post-metadata">

**Author:** ![pbhandar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/76d3ee/32.png) [@pbhandar](https://www.ruby-forum.com/u/pbhandar)\
**Post date:** [May 28, 2009, 5:59pm UTC](https://www.ruby-forum.com/t/process-leak-after-using-session-module/168976/2 "2009-05-28T17:59:43Z")

</div>

On Wed, May 27, 2009 at 4:38 PM, Pra B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> This script has a process leak with a bash session being left open every  
> time I run it. I can’t find a way to close the bash object after I am  
> done. Docs don’t explicitly don’t cover this… or I am missing something  
> simple. Can anyone shed some light on this or point to docs that I may  
> not be aware of? I looked at the readme provided by Sessions module  
> authors so far.

Just a guess here, but try closing your oratab\_file descriptor. The  
bash shell will usually hang around if there are open file descriptors  
or child processes running. If closing the file descriptor does not  
work, then try looking for open sockets or running children.

oratab\_file = Oratab()  
File.open(oratab\_file, ‘r’) do |ofile|  
bash.execute “\>instancestatus-output.txt”  
ofile.each { |oratab\_line|  
…  
}  
end

Blessings,  
TwP

---

<div class="post-metadata">

**Author:** ![pbhandar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/76d3ee/32.png) [@pbhandar](https://www.ruby-forum.com/u/pbhandar)\
**Post date:** [May 28, 2009, 8:56pm UTC](https://www.ruby-forum.com/t/process-leak-after-using-session-module/168976/3 "2009-05-28T20:56:30Z")

</div>

On 28.05.2009 17:58, Tim P. wrote:

> On Wed, May 27, 2009 at 4:38 PM, Pra B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> }  
> end

Guessing here as well: maybe bash.close helps.

My 0.02 EUR…

robert

---

<div class="post-metadata">

**Author:** ![pbhandar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/76d3ee/32.png) [@pbhandar](https://www.ruby-forum.com/u/pbhandar)\
**Post date:** [May 28, 2009, 10:41pm UTC](https://www.ruby-forum.com/t/process-leak-after-using-session-module/168976/4 "2009-05-28T22:41:53Z")

</div>

On 28.05.2009 22:02, Pra B. wrote:

> That was it! Your .02 EUR was wprth a lot for me today. Is there some  
> documentation where I could have found that bit of nugget?

I have no idea: I had this idea of #close and briefly tried to find  
documentation but hit only source code. So I voiced it nevertheless.

The basic reasoning was, if you open the session with Session.new it  
probably also needs to be closed. 🙂

> Thanks a bunch…

You’re welcome! I’m glad my wild guess was of help.

Kind regards

robert

---

<div class="post-metadata">

**Author:** ![pbhandar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/76d3ee/32.png) [@pbhandar](https://www.ruby-forum.com/u/pbhandar)\
**Post date:** [May 28, 2009, 10:02pm UTC](https://www.ruby-forum.com/t/process-leak-after-using-session-module/168976/5 "2009-05-28T22:02:34Z")

</div>

That was it! Your .02 EUR was wprth a lot for me today. Is there some  
documentation where I could have found that bit of nugget?

Thanks a bunch…

Robert K. wrote:

> On 28.05.2009 17:58, Tim P. wrote:
> 
> > On Wed, May 27, 2009 at 4:38 PM, Pra B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > }  
> > end
> 
> Guessing here as well: maybe bash.close helps.
> 
> My 0.02 EUR…
> 
> robert
