Answer the question
In order to leave comments, you need to log in
How to get process name?
How can I return only the process name?
For example: ps -u user
Returns a table.
I only need the process name to display it on the site.
For the output I use a PHP script:
$cmd = "ps -u s" . $server['sid'] . ";";
ssh::exec_cmd($cmd);
$data = trim(ssh::get_output());
$data = explode("\n", $data);
$d['proc'] = 0;
foreach($data as $key => $value)
{
$d['proc'] = $value;
}
Answer the question
In order to leave comments, you need to log in
ps -p $$ -o comm -h
look at the process -p $$ (pid of the current process), display only the column with the command (-o comm), hide the header line (-h)
We do not read mana, we parse through awk, yeah.
With sorting:
ps -u юзер -o comm --sort=-comm --no-headers | head -n 1
I asked myself, I will answer.
So far this is how it turned out:ps -u юзер | awk '{print $4}' | sort -rn | head -1
Your process? Then php.net/manual/ru/function.getmypid.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question