a process's PID never changes while it's running, and when it exits it gets recycled so that it can be used later by another process.
even if the program is in Python or Java, processes always need a binary
executable (like the Python interpreter/JVM/bash) to start. You can set
which binary should run a program with a #!
line like this:
#!/usr/bin/python3 print("banana")
every process except for the one with PID 1 has exactly 1 parent process. child processes inherit a lot of attributes from their parents.
$ ls ../file.py
file.py
relative to?
every process has a working directory, and child processes inherit their working directory from their parent.
kill
PID
), can the process stop itself from being killed?
any process can set signal handlers functions for a given signal (like SIGINT
). You can either use a default handler (like "ignore") or run a custom function. (kill -9
can't be ignored though)
cat
), what directories are looked in to find it?
PATH
environment variable
lots of programs use environment variables for configuration -- for example git uses the EDITOR
environment variable.
child processes inherit environment variables from their parent.
you can see any process's environment variables with
$ ps eww $PID | tr '\0' '\n' # or on Linux: $ cat /proc/$PID/environ
if that process is running as the same user as you. This is good to be aware of if you're putting passwords in environment variables.
any user can see every process's command line arguments, like this:
$ ps -F $PID # or on Linux: $ cat /proc/$PID/cmdline
so they're even less secret than environment variables
you can run two programs which are both appending log lines to the same file.
every open file has an associated offset, and when you read bytes from the file it'll advance the offset
when you start a process on Linux, you have to specify an array of command line arguments (though the array can be empty).
this is why every programming language has the same core interface for command line arguments (an array/list of strings).
a command line argument can be any sequence of bytes (as long as it doesn't contain the 0 byte). Technically if you wanted you could put weird binary data in a command line argument, but usually they're strings.