On a Linux system a C process is started on boot, which creates a fork of itself. It is not a kernal process or something. In most cases a ps -ef show both processes as expecxted, but sometimes it looks like the following:
1258 root 0:00 myproc
1259 root 0:00 [myproc]
i.e. one of the processes surrounded by brackets. According to ps:
If the arguments cannot be located (usually because it has not been set,
as is the case of system processes and/or kernel threads) the command name
is printed within square brackets.
I do not understand what it means when the 'arguments cannot be located'. The process is started always exactly the same, and the fork is always created in the exact same way. How can it happen, that sometimes 'the arguments cannot be located' and sometimes they can?
In addition, the process is always started without any arguments...
Questions I have:
- What do those brackets really mean? Does the process run at all when
/proc/{pid}/cmdlineis empty? - Why do I get those brackets sometimes and not always?
- How/Where to fix this problem?
Additional information:
- The process is always started without any arguments! Just the name of the command
myproc. - The main process seems to run always correct (no brackets around name, executable in
/proc/x/cmdline). - The child process sometimes has its name in brackets.
- The content of
/proc/child-pid/cmdlineof a correct running child process ismyproc. - The content of
/proc/child-pid/cmdlineof an incorrect running child process is empty! - Again: same code, different child processes!
execvesystem call that the process (or any of its ancestors) made, found in/proc/the-pid/cmdlineon Linux. – Stéphane Chazelas Jan 23 '14 at 14:18/proc/the-pid/cmdlinecontains only exactly one word:myproc. So if this name appears in brackets inps -efit means that the argumentmyproccannot be located. Does it mean the executable itself cannot be located? That it is not in$PATH? – Alex Jan 23 '14 at 14:22/proc/x/cmdlineis empty when you see[xxx], wherexxxis the process name (not the first argument to the last command that process executed) as found in/proc/x/stat. You can get an emptycmdlinefor kernel processes (no exec), for the processes that passed an empty list of arguments to the last process they executed, or for processes that altered their argv[] – Stéphane Chazelas Jan 23 '14 at 14:29fork()command create correct child processes and incorrect child processes at random? Please see updated question – Alex Jan 23 '14 at 14:31forkshould copy the arg list from the parent. Sounds like a stack overwrite. You could see that if after the fork, your process writes to areas of memory it's not meant to, likeenvp[0][-1]=1;argv[0][0]=0. The args are at the bottom of the stack, so it's not that difficult to overwrite them by mistake. – Stéphane Chazelas Jan 23 '14 at 14:55/path/to/myproc), then it will most likely have received at least one argument, the argv[0], likely"myproc". It's generally hard to execute a command without any argument (with no argv[0]) – Stéphane Chazelas Jan 23 '14 at 14:59fork. It's not theforkthat makes that disappear, it's probably what your child process does later intentionaly or not that does.valgrindis a good advice indeed. – Stéphane Chazelas Jan 23 '14 at 15:02myprocat a shell prompt, then it received one argument:myproc. – Stéphane Chazelas Jan 23 '14 at 15:06