Execute and kill a process

Execute and kill a process

am 16.08.2007 22:15:17 von Zanna

Hi all,

I need to simulate the execution of code on another thread an the only way I
found is to launch a .php file with popen().

with

$process = popen(...);

the execution starts, but in the .php file may be an infinite loop that I
want to break.
There is the possibility to kill the process?

If the loop is not infinite and the script in the .php file ends I have to
call pclose($process) or the process terminate itself?

If there is another way to simulate multithread it is wellcome, but working
on the system, not via http.

Thanks!

Re: Execute and kill a process

am 16.08.2007 22:22:02 von ivansanchez-alg

Fabio wrote:

> $process = popen(...);
>
> the execution starts, but in the .php file may be an infinite loop that I
> want to break.
> There is the possibility to kill the process?

Use pnctl_fork() and his friends. You'll get the PID of the process, and
you'll be able to kill it based on that.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

El espacio es una ilusión. El espacio en disco es aún más.

Re: Execute and kill a process

am 17.08.2007 01:24:35 von Zanna

"Iván Sánchez Ortega" ha
scritto nel messaggio


> Use pnctl_fork() and his friends. You'll get the PID of the process, and
> you'll be able to kill it based on that.

I already looked at this, but I don't understand how to use it in the way I
need.
PCNTL functions are also not supported by non-Unix platforms (Windows) and I
read somewhere that has some problem with Apache...
Something else?

Re: Execute and kill a process

am 17.08.2007 01:47:37 von ivansanchez-alg

Fabio wrote:

>> Use pnctl_fork() and his friends. You'll get the PID of the process, and
>> you'll be able to kill it based on that.
>
> I already looked at this, but I don't understand how to use it in the way
> I need.

It's just a wrapper to the POSIX fork() system call... Any course about
concurrent programming teaches about forking a process. I suggest you to go
back to the books.

> PCNTL functions are also not supported by non-Unix platforms (Windows) and
> I read somewhere that has some problem with Apache...
> Something else?

Invoke the CreateProcess() w32 API call.

http://www.php.net/manual/en/function.w32api-invoke-function .php
http://msdn2.microsoft.com/en-us/library/ms682425.aspx

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/ ; http://acm.asoc.fi.upm.es/~ivan/
MSN:i_eat_s_p_a_m_for_breakfast@hotmail.com
Jabber:ivansanchez@jabber.org ; ivansanchez@kdetalk.net

Re: Execute and kill a process

am 17.08.2007 01:52:16 von Zanna

"Iván Sánchez Ortega" ha
scritto nel messaggio news:fa2ni8


> Invoke the CreateProcess() w32 API call.
>
> http://www.php.net/manual/en/function.w32api-invoke-function .php
> http://msdn2.microsoft.com/en-us/library/ms682425.aspx

But something that works under all windows and unix???

And then, what is the way to know if I'm under windows or under unix?

Thanks

Re: Execute and kill a process

am 17.08.2007 02:28:50 von ivansanchez-alg

Fabio wrote:

>> Invoke the CreateProcess() w32 API call.
[...]
> But something that works under all windows and unix???

No can do.

> And then, what is the way to know if I'm under windows or under unix?

You're just concerned about creating new processes, so check if the pcntl
library is loaded, then check if the w32api librart is loaded.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

La inspiración es el trabajo.- Charles Baudelaire.