user3686233
user3686233

Reputation: 109

Perl :: Unable to fork 32000 processes

I am writing a Perl script which fork 32000 processes and each processes perform a bunch of operation for 24 hours. But I am unable to fork that many processes. Any workaround? Please note,the code works perfectly fine for fewer number of processes. Here is the error which I am getting:

pty_allocate(nonfatal): posix_openpt(): No space left on device at /usr/local/lib64/perl5/IO/Pty.pm line 24.
pty_allocate(nonfatal): getpt(): No such file or directory at /usr/local/lib64/perl5/IO/Pty.pm line 24.
pty_allocate(nonfatal): getpt(): No such file or directory at /usr/local/lib64/perl5/IO/Pty.pm line 24.
pty_allocate(nonfatal): openpty(): No such file or directory at /usr/local/lib64/perl5/IO/Pty.pm line 24.
pty_allocate(nonfatal): open(/dev/ptmx): No space left on device at /usr/local/lib64/perl5/IO/Pty.pm line 24.

Upvotes: 0

Views: 227

Answers (1)

Dave Sherohman
Dave Sherohman

Reputation: 46187

Your issue isn't with Perl, it's an operating system limitation. Your kernel only allows the allocation of a finite number of ptys, and this is a global (system-wide) limit, not a per-user or per-process limit.

Assuming you are running under Linux, man 7 pty tells us that

In kernels up to and including 2.6.3, this limit is configured at kernel compilation time (CONFIG_UNIX98_PTYS), and the permitted number of pseudoterminals can be up to 2048, with a default setting of 256. Since kernel 2.6.4, the limit is dynamically adjustable via /proc/sys/kernel/pty/max, and a corresponding file, /proc/sys/kernel/pty/nr, indicates how many pseudoterminals are currently in use.

Thus, if you're using a relatively recent (2.6.4 or later) Linux kernel, you should be able to use cat /proc/sys/kernel/pty/max to see your system-wide maximum pty count.

According to this document (I have not tried it myself to verify), you should be able to change the limit by editing /etc/sysctl.conf and adding the line kernel.pty.max = 5120 (or whatever number), then using sysctl -p to reload the sysctl configuration.

But note that each pty requires the allocation of other system resources (memory, file handles, etc.), so increasing the maximum ptys to an arbitrarily large number may do Very Bad Things to the rest of the system.

Upvotes: 6

Related Questions