Sunday, May 25, 2008

Linux geek: using lsof

Well, it seems that if you keep using something for quite a long time, you can discover new features and uses of it, even if you didn't intend to do so.

I have just discovered one quite useful application of the command lsof: For several months, when the codecs of mplayer can't decode a file properly, mplayer crashes and then it is not possible to listen to anything unless I reboot the system. This has been the usual procedure... until now.

The first thing I discovered was that the audio wasn't able to start because some program was using it, judging by the message "Can't open audio device /dev/dsp: Device or resource busy". The second thing that I found out was that whatever program was using the audio device, should list /dev/dsp as one of its processes, so I thought that finding who was using it could solve the problem.

I read some time ago that you can see all of the processes associated with an application by using lsof, so what I did was simply type "lsof /dev/dsp", and... magic!! It told me that mplayer was still alive, and it was using that device!! So, all I had to do was simply kill mplayer with the useful command "kill -9", and that was all...

Nice discovery.

No comments: