# Fw: #39322 [Com]: proc_terminate(): loosing process resource

- Thread: https://externals.io/message/28017
- Original archive: https://news-web.php.net/php.internals/28017
- Started by Nuno Lopes on 2007-02-13T19:27:38+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #28017 — Nuno Lopes — 2007-02-13T19:27:38+00:00

URL: https://externals.io/message/28017#28017

Anything against this: http://mega.ist.utl.pt/~ncpl/php_proc_terminate.txt ?
If not, I'll apply it by the end of the week with some new tests.

Nuno


----- Original Message ----- 
> ID:               39322
> Comment by:       viraptor+phpbug at gmail dot com
> Reported By:      c dot affolter at stepping-stone dot ch
> Status:           Open
> Bug Type:         Documentation problem
> Operating System: Linux 2.4
> PHP Version:      5.1.6
> New Comment:
> 
> I'd rather like to see proc_terminate act like documented:
> 
> "proc_terminate() allows you terminate the process and continue with
> other tasks. You may poll the process (to see if it has stopped yet) by
> using the `proc_get_status()` function."
> 
> If a known workaround is to send posix_kill, which does... exactly what
> proc_terminate is supposed to do, why not implement proc_terminate as:
> 
> stat = proc_get_status(proc);
> if(stat['running']) posix_kill(stat['pid'], sig);
> 
> ?
> + update the $proc options as needed. That would be much more useful.
> Additionaly not every signal actually kills process, so resource should
> not be destroyed after SIGTERM.
> Please correct code, not docs.
> 
> 
> Previous Comments:
> ------------------------------------------------------------------------
> 
> [2006-11-08 14:55:16] tony2001@php.net
> 
> Reclassified as docu problem.
> 
> ------------------------------------------------------------------------
> 
> [2006-10-31 16:22:53] c dot affolter at stepping-stone dot ch
> 
> Description:
> ------------
> After sending a signal via `proc_terminate()` to a process, the process
> resource gets closed immediately.
> This means that calling `proc_get_status()` afterwards, will throw a
> warning about an invalid process resource.
> 
> This behaviour is somewhat cumbersomely, since you're unable to check
> if it was your signal which has caused the process to terminate or if
> the process has stopped.
> 
> Is this a bug or an undocumented behaviour?
> 
> BTW:
> Sending a signal via the shell or through `posix_kill()`, will retain the
> status for the first `proc_get_status()` call. 
> 
> Reproduce code:
> ---------------
> <?php
> $descriptors = array(
>    0 => array('pipe', 'r'),
>    1 => array('pipe', 'w'),
>    2 => array('pipe', 'w'));
> 
> $pipes = array();
> 
> $process = proc_open('/bin/sleep 120', $descriptors, $pipes);
> 
> proc_terminate($process);
> var_dump(proc_get_status($process));
> 
> ?>
> 
> 
> 
> Expected result:
> ----------------
> array(8) {
>  ["command"]=>
>  string(14) "/bin/sleep 120"
>  ["pid"]=>
>  int(23011)
>  ["running"]=>
>  bool(false)
>  ["signaled"]=>
>  bool(true)
>  ["stopped"]=>
>  bool(false)
>  ["exitcode"]=>
>  int(-1)
>  ["termsig"]=>
>  int(15)
>  ["stopsig"]=>
>  int(0)
> }
> 
> Actual result:
> --------------
> Warning: `proc_get_status()`: 7 is not a valid process resource in ...
> 
> 
> ------------------------------------------------------------------------
> 
> 
> -- 
> Edit this bug report at http://bugs.php.net/?id=39322&edit=1

---

## #28018 — Wez Furlong — 2007-02-13T23:02:51+00:00

URL: https://externals.io/message/28017#28018 · In reply to: #28017

Patch looks good to me.

--Wez.


> Anything against this: http://mega.ist.utl.pt/~ncpl/php_proc_terminate.txt ?
> If not, I'll apply it by the end of the week with some new tests.
>
> Nuno
>
>
> ----- Original Message -----
> > […]

---

## #28019 — Nuno Lopes — 2007-02-13T23:19:33+00:00

URL: https://externals.io/message/28017#28019 · In reply to: #28018

OK, thanks for the feedback. It seems now I can commit it with confidence :)
Nuno


----- Original Message ----- 
> Patch looks good to me.
>
> --Wez.
>
> 
> > […]
