Mintty Weirdness

I use Cygwin to emulate a Unix-like terminal on Windows. Even though Cygwin is pretty good in emulating Unix terminal, its UI leaves a lot to be desired for, so I decided to use Mintty on top of Cygwin. Mintty not only looks nicer than Cygwin but it also has some useful features like easy copy/paste, drop & drop of text files and so on.

I installed Mintty through the usual Cygwin package installation process and I saw that it put mintty.exe file under cygwin’s bin folder. When I tried to run Mintty by invoking mintty.exe from Cygwin, it worked fine. Pretty soon, I was changing the terminal properties and making Mintty look like I wanted. So far so good.

The problem started when I created a shortcut to launch Mintty from Windows Start page. I wanted this shortcut to launch Mintty on Cygwin by default. When I clicked on the shortcut, none of the normal Unix commands would work, I would get a “command not found” error from bash. After Googling for a while and some random experiments, I found out that I had to go to shortcut’s properties and change its target to add a dash at the end. So my shortcut’s target is “C:\cygwin64\bin\mintty.exe -”

Don’t know or care why I have to do this but I wish developers put more thought in the first time use experience of their applications/libraries/packages.

Too many open files error and ulimit

I’ve been running some tests on my Mac where I was opening lots of connections from my virtual clients to my server and I suddenly ended up with this error:

java.io.IOException: Too many open files in system

As you guessed, there’s a limit to the number of open files in most of the operating systems. You can see the limit on your machine using ulimit -a. Note the open files limit is 256:

matamel-MacBookPro:etc matamel$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) 6144
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 256
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 266
virtual memory (kbytes, -v) unlimited

And, you can change the open files limit using ulimit -n. In this case, I increased my open files by 10:

matamel-MacBookPro:etc matamel$ ulimit -n 2560
matamel-MacBookPro:etc matamel$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) 6144
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 2560
pipe size (512 bytes, -p) 1
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 266
virtual memory (kbytes, -v) unlimited

Note that this only applies to the shell you’re currently in although I’m sure there’s a way to make this permanent on Mac OS, just didn’t spend the time to look for it. I know that in Suse, you can make this change permanent by adding the following to /etc/security/limits.conf

* soft nofile 10240
* hard nofile 20480

In Windows, I seem to remember that this was controlled by a registry setting called MaxUserPort but might be wrong.