0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

OS X で 同時オープンできるファイル数の上限をあげる

Posted at

背景

RubyでFiberSchedulerを作っている時に、UDPソケットを同時に1000個開こうとしたら、以下のようなエラーがRubyレイヤーで発生した。

Failure/Error: sock = UDPSocket.new(af)
     
Errno::EMFILE:
  Too many open files - socket(2) - udp

1000個同時に開きたい。

解決方法

ulimitコマンドを使う。

現在の設定値の確認

$ ulimit -a -H # ハードリミット (制限を緩めるにはroot権限が必要になる)

-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             65532
-c: core file size (blocks)         unlimited
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       4176
-n: file descriptors                unlimited  ## これ
$ ulimit -a -S # ソフトリミット (強い制限の範囲内であれば、ユーザー自身が制限を緩めることが可能)
-t: cpu time (seconds)              unlimited
-f: file size (blocks)              unlimited
-d: data seg size (kbytes)          unlimited
-s: stack size (kbytes)             8192
-c: core file size (blocks)         0
-v: address space (kbytes)          unlimited
-l: locked-in-memory size (kbytes)  unlimited
-u: processes                       2784
-n: file descriptors                256      ## これ

設定値を変更する

$ ulimit -S -n 1024 # -n -S の順ではだめ

Ref.

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?