Ps efgrep command9/28/2023 ![]() If I'm looking for the main shell, I would generally set it to a variable first so its clear that's the one I want. Which one is correct? It depends on what you are trying to do. Scripts do this sort of thing all the time, see how the first has 3 lines but the second has only 2? This is because the first we are resolving $$ then running the script and finding out "main" shell, but the second we are doing it the other way which of course has a different PID of the child shell and doesn't match the 3802 of the parent. However, you have to be really careful of $$ in scripts because it means "this shell" but the concept of this depends on when and where it is called.Ĭonsider the two commands: $ sh -c "ps -ax | grep $$"ģ658110 pts/0 S+ 0:00 sh -c ps -ax | grep 3802ģ658142 pts/0 S+ 0:00 sh -c ps -ax | grep $$ The -h option is to remove the header line. ps takes the PIDs of the processes you are interested in as command line options so if you know what you want, specify it directly, rather than hope the grep will work. user 4378 4308 0 09:40 pts/2 00:00:00 grep -colorauto 6703 That is the only string that was matched in the output of ps, in other words, grep command itself is the only one on that list. Something as simple as ps -h $$ > catch will probably do it. GNU long options, preceded by two dashes.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |