Friday, December 20, 2013

Concurrently sharing a Linux terminal across different ssh sessions or terminal emulators

How can I share a terminal session in two different terminal emulator windows or ssh sessions?

Why?
I run pianobar on an old laptop to listen to music from Pandora. I usually start pianobar through ssh from another laptop to be able to control it from the other room. However when I am moving between rooms, I have to terminate pianobar across the ssh session and start it locally on the old laptop if I want to control it.

How?
I have been using the "screen" command for some time to maintain sessions across different ssh sessions. It turns out "screen" has a multi-user mode.

To share a terminal, you just follow these steps:
  1. Start "screen" through an ssh session or a local terminal emulator.
  2. Go to the another terminal session and start "screen -x". You will need to specify the tty to attach to if you have started more than one. 
  3. Voila ! These two sessions are identical. You can follow the progress of a command or control it simultaneously from both sessions.
Final note: This requires "screen" to be compiled with multi-user mode support which I have found to be the case for Mac OS X 10.9 and Debian 5. I assume it's enabled by default but just in case.

Back to listening to pianobar now :)

Thursday, December 12, 2013

Building 32-bit ports on 64-bit Mac OS X using Macports

I a big fan of C# and I also happen to be a Mac OS X user. I wanted to build some project that uses EmguCV on Monodevelop. EmguCV is the C# wrapper for the OpenCV library.

Mono is currently 32-bit only so I tried to build OpenCV in 32-bit as well. It turns out OpenCV needs to link to ffmpeg which was built as a 64-bit library by Macports. I got the following error during linking:

ld: warning: ignoring file /opt/local/lib/libavcodec.dylib, file was built for x86_64 which is not the architecture being linked (i386): /opt/local/lib/libavcodec.dylib
After some messing around and reading on Macports documentation, it turns out you can build universal packages (by default universal = i386 + x86_64 but you can change it in macports.conf) by adding one parameter to the port command:
sudo port install ffmpeg +universal
 This rebuilt ffmpeg to include both x86_64 and i386 and solved my problem.

Hope this helps someone else out there.