Signal sending problem
Moderator: General Moderators
Signal sending problem
I am trying to get php to send a signal to a concurrently running c/c++ program. I have tried several ways of attempting this but every time the php route fails.
I can from terminal send the appropriate signal and the c/c++ program(s) will acknowledge receiving the signal (I have custom handlers written for them) but when I try through php it does nothing.
Here's an example of some of the things I've tried:
$y = `./sendsig`;
system("./sendsig", $x);
system("./sikil", $z);
exec("./sendsig");
sendsig is a shell script I wrote that when run from terminal sends the right signal to the c/c++ prog and the program acknowledges the signal.
$y = `./siint`;
system("./siint", $x);
system("./siint", $z);
exec("./"siint);
siint is another c program that I wrote that sends the right signal to the c/c++ program and it acknowledges the signal being received (only when I run siint from terminal.. from php it blunders).
$pid = `pgrep ex`; // this line doesn't work atm so I have $pid set by hand to the process of the c/c++ program
$y = `kill -10 $pid`;
system("kill -10 $pid", $x);
exec("./sendsig");
Is the direct route I tried getting php to send the signal itself, and that didn't work at all.
Does anyone have any ideas? I'm running out of options to get php to send a signal to a program. It's possible that php refuses to send a signal to another program because of lack of permission.. I don't know.
I can from terminal send the appropriate signal and the c/c++ program(s) will acknowledge receiving the signal (I have custom handlers written for them) but when I try through php it does nothing.
Here's an example of some of the things I've tried:
$y = `./sendsig`;
system("./sendsig", $x);
system("./sikil", $z);
exec("./sendsig");
sendsig is a shell script I wrote that when run from terminal sends the right signal to the c/c++ prog and the program acknowledges the signal.
$y = `./siint`;
system("./siint", $x);
system("./siint", $z);
exec("./"siint);
siint is another c program that I wrote that sends the right signal to the c/c++ program and it acknowledges the signal being received (only when I run siint from terminal.. from php it blunders).
$pid = `pgrep ex`; // this line doesn't work atm so I have $pid set by hand to the process of the c/c++ program
$y = `kill -10 $pid`;
system("kill -10 $pid", $x);
exec("./sendsig");
Is the direct route I tried getting php to send the signal itself, and that didn't work at all.
Does anyone have any ideas? I'm running out of options to get php to send a signal to a program. It's possible that php refuses to send a signal to another program because of lack of permission.. I don't know.
Re: Signal sending problem
Try:
I'm pretty sure that Apache user process is not permitted to signal the C program process (supposing it's running under another user) and you will see it in the error message shown by the output of the PHP code above.
Also, SIG 10 is a strange signal to send... http://www.unix.com.ua/orelly/other/pui ... ect-2.html
Code: Select all
echo exec('kill -10 `pgrep ex` 2>&1');Also, SIG 10 is a strange signal to send... http://www.unix.com.ua/orelly/other/pui ... ect-2.html
There are 10 types of people in this world, those who understand binary and those who don't
Re: Signal sending problem
So, how would I have the php message the c program? Or contact it in anyway? What if the c-program was initialized by apache? Signal 10 is a user specified signal, it seemed like a good one to catch.
Re: Signal sending problem
What is the output from the code I gave you above?
If your C program runs under Apache user I think there should be no problems with sending signals to it from PHP.
If your C program runs under Apache user I think there should be no problems with sending signals to it from PHP.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Signal sending problem
Is what my php page outputs after your line. I don't think I can have php run the c program.. because the c program is designed to run forever. All the php functions to run outside programs wait until the command returns.. and this one would never return. Also on that note, I wouldn't know how to obtain the pid for the c program if a php script ran the c program.sh: line 0: kill: ex: arguments must be process or job IDs
I appreciate your input, cause I've banged my head on the keyboard for several days on this problem.
Re: Signal sending problem
moejoe22 wrote:Is what my php page outputs after your line. If I replace the pgrep segment with the pid that I manually input after finding it, the echo displays nothing.sh: line 0: kill: ex: arguments must be process or job IDs
I don't think I can have php run the c program.. because the c program is designed to run forever. All the php functions to run outside programs wait until the command returns.. and this one would never return. Also on that note, I wouldn't know how to obtain the pid for the c program if a php script ran the c program.
I appreciate your input, cause I've banged my head on the keyboard for several days on this problem.
Re: Signal sending problem
I really don't think it's the output of *my* code - it looks like you are trying to run:moejoe22 wrote:Is what my php page outputs after your line.sh: line 0: kill: ex: arguments must be process or job IDs
Code: Select all
kill -10 exCode: Select all
kill -10 `pgrep ex`If you have permition problems you can either use sudo to execute the Bash script as root, or run the C program process under Apache user:
Code: Select all
su www-data -c "/bin/path/to/your/C_program arg1 arg2"There are 10 types of people in this world, those who understand binary and those who don't
Re: Signal sending problem
That output is from
I don't have access to be the super user on this server atm. I will try and use su to become my account and run the exce('kill -10 `pgrep ex`');
. Removing '2>&1' yields no output and the c program doesn't receive the signal.echo exec('kill -10 `pgrep ex` 2>&1');
I don't have access to be the super user on this server atm. I will try and use su to become my account and run the exce('kill -10 `pgrep ex`');
Re: Signal sending problem
what about just sending the signal using posix_kill():
You will have to know the pid though, and I wouldn't recommend to obtain it by grepping the process list. It's much better to make your C program write the pid of its running process somewhere in the well known location on filesystem (like most unix daemons do, in /var/run/) and read it from there.
Code: Select all
$pid = trim(file_get_contents('/var/run/your.program.pid'));
if (!posix_kill($pid, SIGUSR1)) {
echo htmlspecialchars(posix_strerror(posix_get_last_error()));
}