Kyle
Kyle

Reputation: 115

How to keep track of processes started in PHP on server and refer to them later?

I am running a server that allows users to connect via a PHP post request. The PHP file connects to the server and executes a shell command that starts a process. The process is a bio-physics simulation program that takes 15 minutes to run.

My plan is to generate an identifer for each process running and keep track of that process in a database somewhere. My question is, how can I keep track of which processes are running and determine whether or not the process is complete via php?

I am looking for a way to identify processes by name or id. I am not familiar enough with Unix to determine the best way to do this.

Upvotes: 0

Views: 175

Answers (1)

John C
John C

Reputation: 4396

The ps -f command will show the parent process id for all listed processes. If you know the parent process you can easily use this to determine any child processes that were spawned by it.

Eg:

$ ps -f
UID   PID  PPID   C STIME   TTY           TIME CMD
501 65775 65770   0 10:40am ttys000    0:00.11 -bash

My bash shell is running in process id 65775

Lets start another bash from this one...

$ bash
$ ps -f
UID   PID  PPID   C STIME   TTY           TIME CMD
501 65775 65770   0 10:40am ttys000    0:00.11 -bash
501 66207 65775   0 10:44am ttys000    0:00.01 bash

You can see that the new bash is process id (PID) 66207 and it was started by parent process id (PPID) 65775

Upvotes: 1

Related Questions