...
 
Commits (3)
DOCUMENTROOT=$(DESTDIR)/www/pages/lwir16
OWN = -o root -g root
INSTDOCS = 0644
INSTEXE = 0755
SYSCONFDIR =/etc
CONFDIR = $(SYSCONFDIR)/elphel393
INSTALL = install
DOCS= index.html \
lwir16.php
DOCS= index.html
PHP_SCRIPTS_EXE=lwir16.php \
test_int.php \
test_wpipe.php \
test_ps.php
CONFIGS = lwir16.ini
all:
@echo "make all in src"
......@@ -11,6 +23,10 @@ install:
@echo "make install in src"
$(INSTALL) $(OWN) -d $(DOCUMENTROOT)
$(INSTALL) $(OWN) -m $(INSTDOCS) $(DOCS) $(DOCUMENTROOT)
$(INSTALL) $(OWN) -m $(INSTEXE) $(PHP_SCRIPTS_EXE) $(DOCUMENTROOT)
$(INSTALL) -d $(DESTDIR)$(SYSCONFDIR)
$(INSTALL) -d $(DESTDIR)$(CONFDIR)
$(INSTALL) $(OWN) -m $(INSTDOCS) $(CONFIGS) $(DESTDIR)$(CONFDIR)
clean:
@echo "make clean in src"
ips = "192.168.0.41,192.168.0.42,192.168.0.43,192.168.0.44,192.168.0.45"
duration = 100
pre_delay = 5.0
ffc_period = 300.0
ffc_groups = 2
ffc_frames = 8
ffc = 1
debug = 1
# no spaces around commas!
CMD = INIT,START
\ No newline at end of file
This diff is collapsed.
#!/usr/bin/php
<?php
set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
include 'show_source_include.php';
include "elphel_functions_include.php"; // includes curl functions
$pipe_cmd="/tmp/pipe_cmd";
$pipe_response="/tmp/pipe_response";
$mode=0600;
declare(ticks = 1);
pcntl_signal(SIGTERM, "signal_handler");
pcntl_signal(SIGINT, "signal_handler");
function signal_handler($signal) {
switch($signal) {
case SIGTERM:
print "Caught SIGTERM\n";
exit;
case SIGKILL:
print "Caught SIGKILL\n";
exit;
case SIGINT:
print "Caught SIGINT\n";
exit;
}
}
if(file_exists($pipe_cmd)){
unlink($pipe_cmd); //delete pipe if it was already there - waiting prevents signal handling!
}
while(1) {
if(file_exists($pipe_cmd)) {
//block and read from the pipe
$f = fopen($pipe_cmd,"r");
echo "(r) opened cmd\n";
$l = fgets($f);
fclose ($f);
echo "(r) closed cmd\n";
unlink($pipe_cmd); //delete pipe
echo "(r) deleted cmd\n";
if(!file_exists($pipe_response)) {
// create the pipe
umask(0);
posix_mkfifo($pipe_response,$mode);
}
$fr = fopen($pipe_response,"w");
fwrite($fr,"response1: ".$l);
fwrite($fr,"response2: ".$l);
fwrite($fr,"response3: ".$l);
echo "(r) sent responses\n";
sleep(1);
fclose ($fr);
echo "(r) closed response pipe\n";
}
//
}
?>
#!/usr/bin/php
<?php
print_r($argv);
set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
include 'show_source_include.php';
include "elphel_functions_include.php"; // includes curl functions
$name = 'test_ps.php'; // int.php';
$interpreter='php';
echo "\n--------- interpreter=$interpreter, name = $name ----------\n";
$arr = getPIDByName($name, $interpreter, $active_only=false);
// var_dump($arr);
print_r($arr);
$name = 'test_ps.php'; // 'php-cgi';
$interpreter='';
echo "\n--------- interpreter=$interpreter, name = $name ----------\n";
$arr = getPIDByName($name, $interpreter, $active_only=false);
// var_dump($arr);
print_r($arr);
$interpreter='python';
$name = 'tempmon.py';
echo "\n--------- interpreter=$interpreter, name = $name ----------\n";
$arr = getPIDByName($name, $interpreter, $active_only=false);
// var_dump($arr);
print_r($arr);
?>
#!/usr/bin/php
<?php
define('PIPE_CMD', '/tmp/pipe_cmd');
define('PIPE_RESPONSE', '/tmp/pipe_response');
define('PIPE_MODE', 0600);
set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
include 'show_source_include.php';
include "elphel_functions_include.php"; // includes curl functions
$cmd = 'STATUS';
$kw = 'CMD';
if (count($argv) > 2){
$kw = $argv[1];
$cmd = $argv[2];
} else if (count($argv) > 1){
$cmd = $argv[1];
}
$mode=0600;
if(!file_exists(PIPE_CMD)) {
// create the pipe
umask(0);
posix_mkfifo(PIPE_CMD,$mode);
}
if (file_exists(PIPE_RESPONSE)){
unlink(PIPE_RESPONSE); //delete old pipe
}
$f = fopen(PIPE_CMD,"w");
// sleep(1);
$cmds = $kw.' = '.$cmd."\n";
fwrite($f,$cmds);
// sleep (1);
echo "(w) sent commands:\n".$cmds."\n";
fclose ($f);
// sleep(1);
echo "(w) closed\n";
if ($cmd == 'STATUS') {
while (!file_exists(PIPE_RESPONSE)); // just wait
echo "(w) got PIPE_RESPONSE\n";
$fl = file(PIPE_RESPONSE);
var_dump($fl);
unlink(PIPE_RESPONSE); //delete pipe
}
?>
......@@ -26,9 +26,9 @@
*! -----------------------------------------------------------------------------**
*!
*/
// TODO set include path, like in set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
include 'include/show_source_include.php';
include "include/elphel_functions_include.php"; // includes curl functions
set_include_path ( get_include_path () . PATH_SEPARATOR . '/www/pages/include' );
include 'show_source_include.php';
include "elphel_functions_include.php"; // includes curl functions
$minahead = 2;
$PARS_FRAMES = 16;
$maxahead = $PARS_FRAMES - 4; // 3;
......
......@@ -333,4 +333,86 @@ function get_sensors(){
return $sensors;
}
/**
* Locating process(es) by name and optional interpreter name.
*
* @param string name - name of the program/script, both basename and full name are OK.
* @param string $interpreter - name of the interpreter (optional), both basename and full name are OK. This
* parameter is required when script is executed with explicit interpreter (such as in 'php script.php'.
* @param boolean $active_only - skip zombie and kernel thread processes
* @return array of matches, each match may have the following fields:
* 'active' - false for zombies/kernel threads (indicated by [] in COMMAND field), true otherwise
* 'pid' - integer PID of the process ) (first column of ps output)
* 'user' - process owner (second column of ps output)
* 'vsz' - process virtual memory size (multiplied by 1000000 if third column of ps output ends with 'm')
* 'stat' - fourth column of ps output
* 'scmd' - fifth column of the ps output (with enclosing [] removed)
* 'exe'- (optional) called script path if present (enclosed in {} in ps output) when interpreter is invoked from #! line
* 'interpreter' - intrepreter full path if specified or detected from #! by ps
* 'argv' - array of the command line tokens, starting with the program/script path.
*
* Long argument lists are truncated by "ps -w"
*/
function getPIDByName($name, $interpreter="",$active_only=false){
$ss = $interpreter ? ($interpreter.".*".$name) : $name;
exec('ps -w | grep "'.$ss.'"', $arr);
$rslt=array();
$sep = " \n\t";
foreach ($arr as $entry){
// echo $entry."\n";
$active = substr($entry, -1) != ']';
$l = array();
$l['active'] = $active;
$l['pid'] = (int) strtok($entry, $sep);
$l['user'] = strtok($sep);
$vsz= strtok($sep);
$l['vsz'] = (int) $vsz;
if (strchr($vsz,'m')){
$l['vsz'] *=1000000;
}
$l['stat'] = strtok($sep);
$l['scmd'] = trim(trim(strtok('')),'[]'); // rest of the string with leading ' ' removed
// parse command line
$acmd = array();
$tok = strtok($l['scmd'], $sep);
while ($tok !== false){
$acmd[] = $tok;
$tok = strtok($sep);
}
if ($acmd[0][0] == "{"){
$l['exe'] = trim(array_shift($acmd),'{}'); // first token - enclosed in {} executed script that calle interpreter throuh #!
if (!$interpreter) {
$interpreter = $acmd[0];
if (strrpos($interpreter, '/') !== false){
$interpreter = substr($interpreter, strrpos($interpreter, '/') + 1);
}
}
}
if ($interpreter){ // see if interpreter matches
$first_tok = array_shift($acmd); // shifts array, removes first element
$offs = strpos($first_tok,$interpreter);
if ($offs === false){
continue; // interpreter does not match
} else if (($offs >0) && ($first_tok[$offs -1] != '/')){
continue; // interpreter does not match (only ends with)
}
$l['interpreter'] = $first_tok;
}
if (!count($acmd)){
continue; // only interpreter present; // should not get here
}
$argv0 = $acmd[0];
$offs = strpos($argv0,$name);
if ($offs === false){
continue; // program name does not match
} else if (($offs >0) && ($argv0[$offs -1] != '/')){
continue; // program name does not match (only ends with)
}
$l['argv'] = $acmd;
$rslt[] = $l;
}
return $rslt;
}
?>