
Working With Unix Processes

The kernel of your Unix system sits atop the hardware of your computer. It's a middleman for any interactions that need to happen with the hardware. This includes things like writing/reading from the filesystem, sending data over the network, allocating memory, or playing audio over the speakers. Given its power, programs are not allowed direct acc
... See moreJesse 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
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
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
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 dollar
... See moreJesse Storimer • 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
Note that the hard limit on my system for the number of file descriptors is a ridiculously large integer. Is it even possible to open that many? Likely not, I'm sure you'd run into hardware constraints before that many resources
Jesse Storimer • Working With Unix Processes
Just knowing the pid isn't all that useful in itself. So where is it used? A common place you'll find pids in the real world is in log files.
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.