The regex “ owerhr” matches the literal string “ powerhr“. As grep works with regex, we can solve this problem with a regex trick: $ ps -ef | grep -i "owerhr" However, we need to type two grep commands in this way. Of course, we can pipe the result to another grep command with the -v (invert-match) option to discard the grep process: $ ps -ef | grep -i powerhr | grep -v grep This is because the grep process has already started when we launch the command. However, we also notice that the grep command itself appears in the output. Kent 2503000 75711 0 00:37 pts/11 00:00:00 grep -i powerhrĪs the output above shows, we can see the start.sh process. Next, let’s use this approach to find powerHR‘s process: $ ps -ef | grep -i powerhr So next, let’s test the pgrep command with both -a and -f options to find our smartMarketing process: $ pgrep -af MarketingĢ494597 /bin/bash /tmp/test/smartMarketing/start-marketing.shĪdditionally, we can ask pgrep to perform a case-insensitive match with the -i option: $ pgrep -af powerhrĢ455359 /bin/bash /tmp/test/powerHR/start.sh 5. This makes it easier to verify if the found processes are really what we’re looking for. Moreover, if we pass pgrep the -a Option, it’ll print the found PIDs together with the complete command lines of the processes. With the -f option, we can search those Java applications with their real application names, such as pgrep -f intellij. For instance, let’s look at the full command line of an IntelliJ IDE process: /usr/lib/jvm/default/bin/java -classpath /home/kent/javaEnv/intellij/lib/util.jar.(many other jars and arguments). However, the expected names could be in the arguments. For example, if we start some Java applications, all program names are likely the same: “ $JAVA_HOME/bin/java“. In the real world, this could be pretty useful. If we want more information about the process, we need to pass the found PID to other commands, such as ps, as shown above. The pidof command is pretty straightforward. We can verify whether this PID is the one we’re looking for: $ ps -fp 2455359 To solve this problem, we can pass the -x option to the pidof command to make it support reporting PID of named scripts: $ pidof -x start.sh However, we don’t want to run ‘ pidof bash‘, as all current running scripts and shells will be listed. So, for the pidof command, the program running start.sh is /bin/bash. It’s executed by /bin/bash, as defined in the shebang. This is because start.sh is a shell script. Surprisingly, the pidof doesn’t print anything this time. Next, let’s try to find the process of the powerHR application ( start.sh): $ pidof start.sh For example, we know on the *nix systems, the init process has the PID 1, so we can use pidof to verify it: $ pidof init A program name can be a command, script, or executable. Here, we pass the program name to the pidof command. First, of course, pidof needs to know what to find. As its name implies, the pidof command can find the PID of a running program.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |