12 December 2006

Killing System Processes in Ruby

So I have recently had the need to create system process and kill them at times. I have never done this in ruby and it turned out to be fairly easy. In fact, like many things in ruby it was much easier than I was trying to make it. The real problem I was having was trying to figure out what the pid of the system process was. Process.fork returned the pid of the child ruby process that was forked, not the system call that was made inside the fork block, or so I thought. It turns out if you fork and then exec, the pid returned from the fork is the pid of the exec’ed process. This is of course how it should work, I just wanted it to be more tricky than that for some reason. Here is the little class I wrote to test it out.

class ExternalProcesses
def initialize
@pids = []
end

def run_command(cmd)
pid = Process.fork do
exec(cmd)
end
Process.detach(pid)
@pids << pid =" @pids.pop" e =" ExternalProcesses.new">
During the ’sleep 10′ you can verify that this works as expected by opening another terminal and looking at your systems process list.

13 November 2006

Barn Raising

Grandpa left a couple of presure treated 4×4 posts at our house a couple of months ago. I kept looking at them thinking it was a waste to have them just sitting on the ground. What could I do with them? The best thing I could think of was to build a shed. So it was off to Home Depot… A few hundred dollars later and a quite a few hours (spread over a few months) later and I almost have a shed to put my gardening stuff in.

So I really didn’t/don’t know how to build a shed. I just started asking questions to people who I thought might know something about it. I learned a lot from talking to them and then started hammering nails into some boards. It is going pretty well. The real problem is that I don’t have any time to work on it during the day, and it gets dark by 5:00 now. So Saturday is the only real time I have to work on it. Well, I will persevere and hopefully have it done before Christmas!