Controlling processes via the /proc filesystem

Implemented by the Process Manager component of procnto, the /proc virtual filesystem lets you access and control every process and thread running within the system.

The /proc filesystem manifests each process currently running on the system as a directory whose name is the numerical process ID (in decimal) of the process. Inside this directory, you'll find the following files:

The address space that contains the process's entire memory space.
The arguments passed to the process, separated by null characters. For example:
# pidin -p 28687 arg
      pid Arguments
    28687 io-pkt-v6-hc -d abc100 mac=96a414016206
# echo `cat /proc/28687/cmdline`
A file that you can use for devctl() commands to access processes and their threads.
The path of the executable file used to run the process. For example:
# echo `cat /proc/28687/exefile`
A detailed view of every page in a process's address space.
A detailed view of the process's mappings.
A view of the process's virtual memory.

You can use the following standard functions to access the files in the /proc filesystem:

Function Purpose
open() Establish a file descriptor to a process
read() Read data from the process's address space
write() Write data to the process's address space
stat() Return struct stat information
lseek() Establish a position within the process's address space for further operations
devctl() Manipulate a process or thread
close() Release a file descriptor

Ancillary functions (such as readdir(), opendir(), and so on) are supported on the directory /proc itself—this aids in implementing commands such as ls.

Note: In QNX Neutrino 7.0 or later, you must open the appropriate file (e.g., /proc/pid/ctl), not the /proc/pid directory.

When you start procnto, you can use the following options to specify the umask to use for the /proc/pid/* files.

Controls the umask for cmdline and cctl. The default is 0022.
Controls the umask for as, exefile, mappings, pmap and vmstat. The default is 0066.

You can use chmod to drop permissions on the as and ctl files, but you can't then regain the permissions.

In order to read or write data from or to the process, you must have opened the file descriptor in the appropriate mode. You must also have appropriate privileges to open the particular process. In QNX Neutrino 7.0.1 or later, access is controlled to a limited extent by POSIX permissions but mainly by abilities (see procmgr_ability() in the C Library Reference):

Only one process can have a /proc/pid/as or /proc/pid/ctl file open for writing at a time.