lundi 1 août 2016

Bash how to get full script name from PID

I have this php function that checks the script's name from the given PID, and compares it to itself.

function isRunning($pid) {
    $filename = exec('ps -p '.$pid.' -o "%c"');
    $self = basename($_SERVER['SCRIPT_NAME']);
    return ($filename == $self) ? TRUE : FALSE;
}

From what I know, I usually use this command to get the script name from the PID:

ps -o PID -o "%c"

It returns me the filename, but only the first 15 characters. Since my script's name is

daily_system_check.php

the function always returns FALSE, because it's comparing itself with

daily_system_ch

Is there another bash command for Centos 6 that will return me script's full name?

Aucun commentaire:

Enregistrer un commentaire