![]() There's no significance in picking the first character to do this with. To reiterate the point, you can do all sorts of crazy stuff with grep. If you remove the C, it won't match though, because "cron", starts with a c: ps aux | grep ron You can put whatever you want in the brackets, as long as it contains the c: ps aux | grep ron It does not match your request though, because your request is ron That matches cron, because cron contains a c, and then "ron". ^ That matches itself, because your own command contains "cron" ps aux | grep ron Similarly, you could do any other combination of characters. ![]() So writing means it will accept any charcter, but only c is specified. In grep (and most regular expression engines), you can specify brackets to let it know that you'll accept ANY character in the brackets. Think about that, why would it? Imagine if you were piping a hundred gigabytes of data? It does not execute the ps command, store the result in memory, and them pass it to grep. Linux then maps the standard output (STDOUT) of "ps -ef" to the standard input (STDIN) of the grep command. Linux is executing the "grep" command before the ps -ef command. Hopefully this long response clarifies the shell pipe process a bit. GNU grep does not have any string matching limit, and on some platforms (I think Solaris, HPUX, aix) the limit of the string is given by the "$COLUMN" variable or by the terminal's screen width. grep does not match its search pattern from the stdin because a string containing "c" followed by "ron" it's not found, but it has found a string containing "c" followed by "]ron".ps sends data (that even contains the string grep ron) to grep.Like the first example, but in this case it will break the match string returned by ps because: The attribute passed instructs grep to match something containing "c" followed by "ron". grep matches its search pattern from the STDIN and it matches the string "grep cron" because of the "cron" attribute you passed in to grep: you are instructing grep to match the "cron" string and it does because "grep cron" is a string returned by ps at the time grep has started its execution. ![]() ps sends data (that even contains the string "grep cron") to grep.Since ps is written to send on the standard output info on each running process, while grep is written to get on its standard input something that has to match a given pattern, you'll have the answer to your first question: The read side of the pipe is attached to the STDIN of the grep command and the write side is attached to the STDOUT of the ps command: the standard output of the ps command is attached to the standard input of the grep command. Now you have the shell process with two children (that are siblings) where the first one is the ps command with -ef attributes and the second one is the grep command with the cron attribute. This newly generated child process close()s its standard input file descriptor (fd 0) and attaches the fd 0 to the read side of the pipe created by the father process (the shell where you executed the command).Īfter doing so it will exec() the first (in your case) grep command found in your PATH environment variable. So, you now have the shell process with a child that is, in your case, the ps command with -ef attributes.Īt this point, the parent (the shell) fork()s again. ![]() With the exec() call the process will become the command you executed. After doing so it will exec() the first (in your case) ps command found in your PATH environment variable. This is possible because the fork() syscall will maintain, for each, a valid open file descriptor (the pipe fd in this case). This new generated child process will close() its standard output file descriptor (fd 1) and attach the fd 1 to the write side of the pipe created by the father process (the shell where you executed the command). Will execute the pipe() call to create a FIFO, then it will fork() (make a running copy of itself). (.I assume bash in your case, due to the color attribute of grep I think you are running a gnu system like a linux distribution, but it's the same on other unix/shell as well.) When you execute the command: ps -ef | grep cron ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |