Processes and threads:Processes are started with Threads are created with While a process is running it is usually in one of the following states:
Viewing processes:
Attributes of processes/threads:
/proc entries for processes (
|
/proc/[0-9]+ |
Process directories |
/proc/self |
Symlink to the current processes own proc entry. |
/proc/*/fd |
Links to a processes open files. |
/proc/*/cwd |
Link to the processes current working directory. |
Signals are like 1/2 bit messages to a process that can have one of the following effects (called dispositions):
Normal signals number from 1 to 31, and many have default actions, SIGKILL
(i.e. terminate with extreme prejudice) and SIGSTOP (stop execution)
cannot be caught, blocked or ignored.
> kill [ -signal ] pid [ pid... ]
> killall name
> pgrep
> pkill
Each process or set of processes under a specific user ID have a set amount of resource limits that might be modified upward or downward. Some resources can be made unlimited and some can only be modified downward unless you are the super-user:
Normally the resource limits should be modified by the shell builtin limit
(c-shells) or ulimit (Bourne shells such as bash.)
| Useful limits | |
|---|---|
| core file size | Size of core file if program dies and should dump a core file |
| data seg size | Maximum data segment size of a process |
| scheduling priority | Default niceness for programs |
| file size | Maximum size of a file that a process can create/write to |
| max memory size | Maximum amount of real memory a process can consume |
| open files | Maximum number of open files for a process |
| pipe size | Memory size in 512 byte blocks for a pipe queue |
| stack size | Maximum size of a processes stack |
| cpu time | The amount of CPU time a process may consume |
| max user processes | Maximum number of processes this uid may use at any given time |
| virtual memory | Maximum amount of virtual memory a process can consume |
> prlimit
(tcsh) > limit
(bash) > ulimit
> nice
> renice
> ionice
-c class-n level (0-7 for best-effort or realtime)
class (3) idle Lowest priority (2) best-effort Normal (8 levels, 0 being highest, 7 lowest) (1) realtime Highest (8 levels)
man 5 coreWhen a program dies due to an error in the program, such as from a segmentation fault
(attempting to access memory not allocated to the process,) it may be allowed to dump
an image of its memory to a file, called a core dump, which can then be accessed via
a debugger, such as gdb to help debug the cause of the fault. This can be very
useful to debug a long-running program where one may wish to run the program in the
background (such as a daemon) and not wait in a debugger for it to fail.
The core file will usually be written into the processes current working directory at the time of the program fault.
NOTE: Setuid processes cannot dump core (they create 0 byte corefiles,) unless
/proc/sys/fs/suid_dumpable is set. Read man core(5) for other limitations. Be sure
that core files generated by privileged processes cannot be access by a normal user as
the core file could contain sensitive information, such as hashed passwords, private
keys, etc.
(tcsh) > limit coredumpsize unlimited
(bash) > ulimit -c unlimited
The above will let processes generate core-dumps for debugging.
> gcc -ggdb -o crash crash.c
> limit coredumpsize unlimited
> ./crash
Segmentation fault (core dumped)
> gdb ./crash core
...
(gdb) where, etc.