D
D
DrunkMaster2016-04-26 23:12:45
linux
DrunkMaster, 2016-04-26 23:12:45

Is it possible to access PID in linux from PHP?

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 2788 root      15  -5     0    0    0 S  2.0  0.0 404:43.97 md3_raid1
 7961 root      20   0  5964 2528 1684 R  2.0  0.2   0:00.14 top
 6629 root      20   0  8612 2884 2096 S  0.7  0.3   0:00.96 dovecot-auth
   57 root      15  -5     0    0    0 S  0.3  0.0   4:36.10 kblockd/0
 8703 ulogd     20   0 17700 4216  656 S  0.3  0.4  87:23.98 ulogd
11336 ldap      20   0  394M  15M 8292 S  0.3  1.5   5:29.28 slapd
25757 ldap      20   0  394M  15M 8292 S  0.3  1.5   5:11.71 slapd

There is a task to check the php script for the presence or absence of a certain process in the system. Can this be done somehow?
Is there access from php to commands like kill the process, etc., for example kill 11336

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nazar Mokrinsky, 2016-04-26
@nazarpc

exec(), shell_exec() & co are not suitable?

D
Dmitry, 2016-04-27
@thewind

php.net/manual/ru/function.getmypid.php or, as already mentioned, exec() and execute ps -aux | grep "php"

G
Grigory Esin, 2016-04-27
@xotey83

If there is a dira /proc/<pid>.
For each running process in Linux, the above dira is created. Inside are files that contain a lot of interesting things. Look at the contents of the directory yourself - there is a storehouse of information about the process.
To send signals to processes, you can use the posix_kill function (see the description in the puff manual). If this function is not available, then use exec, system, shell_exec, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question