
Working With Unix Processes

Any time that you open a resource in a running process it is assigned a file descriptor number. File descriptors are NOT shared between unrelated processes, they live and die with the process they are bound to, just as any open resources for a process are closed when it exits. There are special semantics for file descriptor sharing when you fork a
... 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 Ter
... See moreJesse Storimer • Working With Unix Processes
Environment, in this sense, refers to what's known as 'environment variables'. Environment variables are key-value pairs that hold data for a process. Every process inherits environment variables from its parent. They are set by a parent process and inherited by its child processes. Environment variables are per-process and are global to each proce
... See moreJesse Storimer • Working With Unix Processes
Every Unix process comes with three open resources. These are your standard input (STDIN), standard output (STDOUT), and standard error (STDERR) resources. These standard resources exist for a very important reason that we take for granted today. STDIN provides a generic way to read input from keyboard devices or pipes, STDOUT and STDERR provide ge
... See moreJesse Storimer • Working With Unix Processes
Set the maximum number of open files to 3. We know this # will be maxed out because the standard streams occupy # the first three file descriptors. Process.setrlimit(:NOFILE, 3) File.open('/dev/null') outputs: Errno::EMFILE: Too many open files - /dev/null
Jesse Storimer • Working With Unix Processes
There are no system calls for directly manipulating environment variables, but the C library functions setenv(3) and getenv(3) do the brunt of the work. Also have a look at environ(7) for an overview.
Jesse Storimer • Working With Unix Processes
The takeaway here is that system calls allow your user-space programs to interact indirectly with the hardware of your computer, via the kernel.
Jesse Storimer • Working With Unix Processes
In the last chapter we looked at the fact that open resources are represented by file descriptors. You may have noticed that when resources aren't being closed the file descriptor numbers continue to increase. It begs the question: how many file descriptors can one process have? The answer depends on your system configuration, but the important poi
... See moreJesse Storimer • Working With Unix Processes
Ruby's Process.ppid maps to getppid(2).