a question about ps -C
am 17.09.2007 23:42:56 von Tribulations
Hi everybody,
I have two questions:
- firstly, my second question does not exactly match with this newsgroup.
Where to post this question next time?
- secondly: my real question: "su -C foo" does detect processes which name
is exactly "foo". The problem is when the name contains spaces: it does not
work at all. For example, edit a file named "foo.txt" with vi:
$ vi foo.txt
And then in another terminal search the corresponding process:
$ ps -C 'vi foo.txt'
It does not work: it detects all vi processes, because it takes vi and
foo.txt as two members of a list. I have tried to escape the space: same
result.
Have you got a solution?
Thanks
--
TP (Tribulations Parallèles)
"Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert).
Re: a question about ps -C
am 17.09.2007 23:48:13 von Tribulations
TP wrote:
> Have you got a solution?
I mean, a solution without all the grep machinery; a solution *with* ps -C.
Or ps -C does not work with names containing spaces? I have googled without
result.
--
TP (Tribulations Parallèles)
"Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert).
Re: a question about ps -C
am 18.09.2007 04:46:49 von Barry Margolin
In article <1093s4-lip.ln1@rama.nodalpoint>,
TP wrote:
> Hi everybody,
>
> I have two questions:
> - firstly, my second question does not exactly match with this newsgroup.
> Where to post this question next time?
> - secondly: my real question: "su -C foo" does detect processes which name
> is exactly "foo". The problem is when the name contains spaces: it does not
> work at all. For example, edit a file named "foo.txt" with vi:
>
> $ vi foo.txt
>
> And then in another terminal search the corresponding process:
>
> $ ps -C 'vi foo.txt'
>
> It does not work: it detects all vi processes, because it takes vi and
> foo.txt as two members of a list. I have tried to escape the space: same
> result.
>
> Have you got a solution?
>
> Thanks
Are you really running a program named "vi foo.txt"? foo.txt looks like
an argument, not part of the program name.
The -C option only matches against the executable name, not the entire
command line. Since programs with spaces in the name are extremely rare
on Linux, treating space as a delimiter makes sense. However, if Apple
ports this option to OS X they'll probably want to fix it.
--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Re: a question about ps -C
am 18.09.2007 07:38:02 von Tribulations
Barry Margolin wrote:
> Are you really running a program named "vi foo.txt"? foo.txt looks like
> an argument, not part of the program name.
I see what you mean. But I am not sure. Indeed, if you type:
$ ps a -o command
You will see "vi foo.txt" in the list.
There is another way to see this: "vi foo.txt" is in the "COMMAND" column
of "ps aux".
So, it seems that "vi foo.txt" is a command (in the ps sense), but it is not
recognized by ps -C.
Do I miss something?
--
TP (Tribulations Parallèles)
"Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert).
Re: a question about ps -C
am 18.09.2007 15:23:11 von Antonio Maschio
ps -C vi | grep foo.txt
Maybe this works?
Re: a question about ps -C
am 18.09.2007 15:39:10 von Tribulations
Antonio Maschio wrote:
> ps -C vi | grep foo.txt
>
> Maybe this works?
Thanks, I think that finally I will be compelled to use grep; but I am
surprised that ps has a contradictory definition of what a "command" is
("vi foo.txt" in the COMMAND column in ps aux, but "vi" or "foo.txt"
in "ps -C "vi foo.txt").
--
TP (Tribulations Parallèles)
"Allez, Monsieur, allez, et la foi vous viendra." (D'Alembert).
Re: a question about ps -C
am 18.09.2007 15:59:59 von Scott McMillan
On Tue, 18 Sep 2007 07:38:02 +0200, TP
wrote:
>Barry Margolin wrote:
>
>> Are you really running a program named "vi foo.txt"? foo.txt looks like
>> an argument, not part of the program name.
>
>I see what you mean. But I am not sure. Indeed, if you type:
>
>$ ps a -o command
>
>You will see "vi foo.txt" in the list.
>There is another way to see this: "vi foo.txt" is in the "COMMAND" column
>of "ps aux".
>
>So, it seems that "vi foo.txt" is a command (in the ps sense), but it is not
>recognized by ps -C.
vi is the command, foo.txt is the argument to the command. From 'man
ps':
-C cmdlist Select by command name.
This selects the processes whose *executable* name is
given in cmdlist.
....vi is the only executable in your example.
If you want a particular command *and* it's arguments you might try
ps -ef | grep
Scott McMillan
Re: a question about ps -C
am 18.09.2007 17:02:32 von Stephane CHAZELAS
2007-09-18, 15:39(+02), TP:
> Antonio Maschio wrote:
>
>> ps -C vi | grep foo.txt
>>
>> Maybe this works?
>
> Thanks, I think that finally I will be compelled to use grep; but I am
> surprised that ps has a contradictory definition of what a "command" is
> ("vi foo.txt" in the COMMAND column in ps aux, but "vi" or "foo.txt"
> in "ps -C "vi foo.txt").
ps -o command
is a non-standard alias for
ps -o args
If you want the command, it's ps -o comm
ps -C is not POSIX, but it might have been in some standard
given that you can find it in several Unices and that HPUX for
instance enables it in UNIX95 mode.
On Linux, the output of ps -o comm is extracted from
/proc//status. I think it is derived from the basename of
the path of the command as passed to the last execve(2) system
call made by the process but may be modified for instance via a
call to the Linux specific prctl(2) system call. In particular,
at least on Linux, it is independant from the argv[0] passed to
the last execve() called by the process. So Linux ps doesn't
seem to be POSIX conformant in that regards, as it's meant to be
argv[0].
--
Stéphane