[SUMMARY] Output of ps

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi All,
Many thanks to the following people who give me kind help.
Patrice Neff
Michael Hinz
John Madden
Partically Patrice Neff give me very nice explanation of it.
I paste his answer here and summarize it briefly as follows.
In the output of ps, the command names enclosed by []
are kernel threads or the command name are kind of guessed.

Cherrs,
--Wen

----- Original Message ----- 
From: "Patrice Neff" <mailinglists@patrice.ch>


> "Wen Guangcheng" <wen.guangcheng@cnt.sp.qnes.nec.co.jp> writes:
>
> > Someone tell me that the ones enclosed by [] are kernel threads.
> > But actually I create a child process by fork&exec scheme.
> > In the child process if I use execl("/home/wen/myjob", "myjob", NULL)
> > to execute myjob, myjob is not enclosed by []. But if I use
> > execv("/home/wen/myjob", NULL), then myjob is enclosed by [].
> > I really don't know the difference between them.
>
> Well the second one does not have a program now in its command line
> arguments. So the brackets could mean that the program name was kind
> of guessed.
>
> Later...
>
> Okay, I have just downloaded the source and read it a bit (package
> procps in Debian). The following function is relevant (I hope your
> Outlook Express does not break the lines).
>
> ,----[ proc/escape.c ]
> | int escape_command(char *restrict const outbuf,
> |        const proc_t *restrict const pp,
> |        nt bytes, int glyphs, unsigned flags){
> |   int overhead = 1;  // the trailing NUL
> |   int end = 0;
> |
> |   if(bytes > glyphs+1) bytes=glyphs+1; // FIXME: assumes 8-bit locale
> |
> |   if(flags & ESC_ARGS){
> |     const char **lc = (const char**)pp->cmdline;
> |     if(lc && *lc) return escape_strlist(outbuf, lc, bytes);
> |   }
> |   if(flags & ESC_BRACKETS){
> |     overhead += 2;
> |   }
> |   if(flags & ESC_DEFUNCT){
> |     if(pp->state=='Z') overhead += 10;    // chars in " <defunct>"
> |     else flags &= ~ESC_DEFUNCT;
> |   }
> |   if(overhead >= bytes){  // if no room for even one byte of the command
name
> |     // you'd damn well better have _some_ space
> |     outbuf[0] = '-';
> |     outbuf[1] = '\0';
> |     return 1;
> |   }
> |   if(flags & ESC_BRACKETS){
> |     outbuf[end++] = '[';
> |   }
> |   end += escape_str(outbuf+end, pp->cmd, bytes-overhead,
glyphs-overhead+1);
> |
> |   // Hmmm, do we want "[foo] <defunct>" or "[foo <defunct>]"?
> |   if(flags & ESC_BRACKETS){
> |     outbuf[end++] = ']';
> |   }
> |   if(flags & ESC_DEFUNCT){
> |     memcpy(outbuf+end, " <defunct>", 10);
> |     end += 10;
> |   }
> |
> |   outbuf[end] = '\0';
> |   return end;  // bytes or glyphs, not including the NUL
> | }
> `----
>
> If the argument ESC_ARGS is set (which usually is the case for ps) it
> tried to read the function name from the command line. If this does
> not succeed, and if ESC_BRACKETS is set (which again usually is the
> case for ps) the true command name is taken and put in brackets.
>
> Try the command line option -c which stands for "true command line
> name" according to the man page. This does not output any square
> brackets and might even give different results from the normal
> output. One example would be
>   execl("/home/wen/myjob", "yourjob", NULL)
> This will return yourjob usually but myjob with -c.
>
> Regards,
> Patrice
>
> -- 
> Jesus answered, "I am the way and the truth and the life. No one comes
> to the Father except through me."               (The Bible, John 14:6)
>
_______________________________________________
LinuxManagers mailing list - http://www.linuxmanagers.org
submissions: LinuxManagers@linuxmanagers.org
subscribe/unsubscribe: http://www.linuxmanagers.org/mailman/listinfo/linuxmanagers

[Index of Archives]     [Kernel]     [Linux SCSI]     [Video 4 Linux]     [Linux Admin]     [Yosemite News]

  Powered by Linux