Linux Shell Programming Example-get process ID

Source: Internet
Author: User

Today, I learned a little bit about the shell programming under Linux and simply recorded the test cases.

1. Edit the shell script file as follows:

#!/bin/bash
echo "Hello Bash Linux"
echo "No. 0 parameter: $ A"
echo "First parameter: $ $"
echo "Current child shell process: $$"

#pidarr = ' PS x | awk ' {print '} '
pidarr=$ (ps x | awk ' {print $} ')
Echo $pidadd
For ID in $pidarr
Do
echo "$id"
Done

2. Save As file Test.bash

3. Make the file have an execution property, use the following command

chmod +x Test.bash

Sample Script Description:

(1) The first line of #!/bin/bash is a fixed format for the script file, indicating that there is bash in the bin directory to perform

(2) The 8th line of pidarr=$ (PS x | awk ' {print $} ') represents the PS x | The results of awk ' {print '} ' are stored in the variable Pidarr, where the awk command is a useful command, and the detailed use of the method can be Baidu

  

Linux Shell Programming Example-get process ID

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.