In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this "Linux shell and process case Analysis" article, so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "Linux shell and process case Analysis" article.
Run a few commands here first:
Print login process (always exists until login exits) ID
George.guo@ls:~$ echo $PPID3411george.guo@ls:~$ ps-aux | grep 3411 george.+ 3411 0.0 99004 4520? S 11:00 0:00 sshd: george.guo@pts/46
Print the shell process out of fork (always exists until the login exits)
George.guo@ls:~$ echo $3412 george.guofulssaw aux $ps-aux | grep 3412 george.+ 3412 0.5 0.0 21380 5120 pts/46 Ss 11:00 0:00-bash
As can be seen from the above commands:
The login process ID is 3411, which creates the bash shell child process 3412. Future script execution
3412 We call it the main shell here, which initiates the shell process processing script.
(note: in bash, the PID of the child shell process is stored in a special variable'$$', and the PPID stores the ID of the child shell parent process. )
Let's write two Mini Program to verify:
George.guo@ls:~$ cat yes.c
# include#include#include # includeint main () {pid_t pid; pid_t ppid; pid = getpid (); ppid = getppid (); system (". / test"); / / system will fork a process for exec. / test printf ("yes pid =% d, yes ppid =% d\ n", pid, ppid);}
George.guo@ls:~$ cat test
#! / bin/bashecho "PID of this script: $$" echo "test's PPID (system's fork id) = $PPID" echo "tests's pid = $$
The running results are as follows:
George.guo@ls~$. / yes
PID of this script: 6082tests PPID (system's fork id) = 6081echo tests self pid is 6082yes PID = 6080, yes PPID = 3412
It can be seen that the parent process ID of the yes process is 3412, that is, the bash bash child process of the login process fork, the main shell. This is because
The yes is executed by the master shell. The yes process ID is 6080, the system is called, and the fork child shell ID is 6081.
For system calls:
Running the command with system () requires the creation of at least two processes. One for running shell (where the ID is 6081)
The other one or more is used for commands executed by shell (in this case, a child shell, the script test itself).
The script test itself process ID is 6082.
The above is about the content of this article on "shell and process case Analysis of Linux". I believe we all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.