
Working With Unix Processes

What's the difference? Glad you asked. The soft limit isn't really a limit. Meaning that if you exceed the soft limit (in this case by opening more than 2560 resources at once) an exception will be raised, but you can always change that limit if you want
Jesse Storimer • Working With Unix Processes
In much the same way as pids represent running processes, file descriptors represent open files.
Jesse Storimer • Working With Unix Processes
Ruby's Process.pid maps to getpid(2). There is also a global variable that holds the value of the current pid. You can access it with $$. Ruby inherits this behaviour from other languages before it (both Perl and bash support $$), however I avoid it when possible. Typing out Process.pid in full is much more expressive of your intent than the
... See moreJesse Storimer • Working With Unix Processes
there are many sections to the Unix manpages. Here's a look at the most commonly used sections of the manpages for FreeBSD and Linux systems: Section 1: General Commands Section 2: System Calls Section 3: C Library Functions Section 4: Special Files So Section 1 is for general commands (a.k.a. shell commands). If I wanted to refer you to the manual
... See moreJesse Storimer • Working With Unix Processes
In the majority of cases the parent process for a given process is the process that invoked it. For example, you're an OSX user who starts up Terminal.app and lands in a bash prompt. Since everything is a process that action started a new Terminal.app process, which in turn started a bash process. The parent of that new bash process will be the
... See moreJesse Storimer • Working With Unix Processes
You can use these same methods to check and modify limits on other system resources. Some common ones are: # The maximum number of simultaneous processes # allowed for the current user. Process.getrlimit(:NPROC) # The largest size file that may be created. Process.getrlimit(:FSIZE) # The maximum size of the stack segment of the # process.
... See moreJesse Storimer • Working With Unix Processes
You can see that we set a new limit for the number of open files, and upon asking for that limit again both the hard limit and the soft limit were set to the new value 4096. We can optionally pass a third argument to Process.setrlimit specifying a new hard limit as well, assuming we have the permissions to do so. Note that lowering the hard limit,
... See moreJesse Storimer • Working With Unix Processes
Every process on the system has a name. For example, when you start up an irb session that process is given the name 'irb'. The neat thing about process names is that they can be changed at runtime and used as a method of communication. In Ruby you can access the name of the current process in the $PROGRAM_NAME variable. Similarly, you can assign a
... See moreJesse Storimer • Working With Unix Processes
Given the above, file descriptors are sometimes called 'open file descriptors'. This is a bit of misnomer since there is no such thing as a 'closed file descriptor'. In fact, trying to read the file descriptor number from a closed resource will raise an exception: passwd = File.open('/etc/passwd') puts passwd.fileno passwd.close puts passwd.fileno
... See more