
Working With Unix Processes

Environment variables are often used as a generic way to accept input into a command-line program. Any terminal (on Unix or Windows) already supports them and most programmers are familiar with them. Using environment variables is often less overhead than explicitly parsing command line options.
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
Many methods on Ruby's IO class map to system calls of the same name. These include open(2), close(2), read(2), write(2), pipe(2), fsync(2), stat(2), among others.
Jesse Storimer • Working With Unix Processes
Every process has access to a special array called ARGV. Other programming languages may implement it slightly differently, but every one has something called 'argv'. argv is a short form for 'argument vector'. In other words: a vector, or array, of arguments. It holds the arguments that were passed in to the current process on the command line. He
... See moreJesse Storimer • Working With Unix Processes
The same thing, with places reversed! ENV['MESSAGE'] = 'wing it' system "echo $MESSAGE"
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
File descriptors are at the core of network programming using sockets, pipes, etc. and are also at the core of any file system operations. Hence, they are used by every running process and are at the core of most of the interesting stuff you can do with a computer.
Jesse 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
The VAR=value syntax is the bash way of setting environment variables. The same thing can be accomplished in Ruby using the ENV constant.