.. highlight:: console .. role:: bash(code) :language: bash :class: highlight Unix processes -------------- .. \begin{itemize} \item Tree structure again --- cut the root to kill the branches \item Every branch (process) has an ID number \item Signals: :kbd:`kill} and :kbd:`pkill} \item Detaching \item Environment propagation: :kbd:`export} \item A process can't affect the environment of its parent \end{itemize} Process control ~~~~~~~~~~~~~~~ .. You should now know something about how Unix processes work. Let's see the processes that are running on your system:: $ ps -aux As usual, look at :command:`man` for the option switches. You can see how the processes are forked from their parents by adding the :kbd:`f` option to our :command:`ps` command:: $ ps -axf | less -S which will show a nice tree. Try using :command:`grep` via a pipe to get information about a particular process name, note that the grep itself will often match as well. Newer systems may have a command called :command:`pgrep`, which is neater. A handy interactive tool for looking at processes is :command:`top`; you'll end up using it a lot to work out what's burning all your CPU or eating all your memory! :command:`top` will show a regularly updating process list, you get back to the terminal by hitting :kbd:`q`. Processes can either be in the :dfn:`background` or :dfn:`foreground`. If the latter, the shell will not prompt again until they have finished: try running :bash:`gedit` and then re-focus the shell window. Your typing now isn't registering as shell commands, it's just appearing in the window while the editor sits there doing nothing. This is where the *run command in the background* syntax comes in. Close gedit with a click (or highlight the terminal and press :kbd:`Ctrl-c` to kill the foreground process), then try it again with:: $ gedit & The terminal might get some messages written to it by gedit, but you should still be able to run commands: gedit is in the background. If you forget to put the :kbd:`&` on the end, you can pause the foreground process with :kbd:`Ctrl-z`, and then put it into the background with :command:`bg`. The corresponding command :command:`fg` will bring the most recent backgrounded command into the foreground. If a foreground process locks up so badly that you can't even background it, you open another terminal and use a combination of :command:`ps` and the :command:`kill` or :command:`pkill` commands to kill the offending process or its parent.