A
A
Alexander Nazarov2017-09-15 00:54:26
linux
Alexander Nazarov, 2017-09-15 00:54:26

How to get process name?

How can I return only the process name?
For example: ps -u userReturns a table.
e6260b1d862d4d27ab6e7625e5aebf0a.pngI 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;
        }

Maybe you can immediately get the name or filter it somehow in the loop?
Who knows, tell me.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Saboteur, 2017-09-15
@wergio

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)

C
chupasaurus, 2017-09-15
@chupasaurus

We do not read mana, we parse through awk, yeah.
With sorting:

ps -u юзер -o comm --sort=-comm --no-headers | head -n 1

A
Alexander Nazarov, 2017-09-15
@wergio

I asked myself, I will answer.
So far this is how it turned out:
ps -u юзер | awk '{print $4}' | sort -rn | head -1

K
Kirill Nesmeyanov, 2017-09-15
@SerafimArts

Your process? Then php.net/manual/ru/function.getmypid.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question