Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Linux \ Getting Started with Linux system to learn: how to get the process ID (PID) in the script     - Spring Data study notes -Helloworld (Programming)

- Build your own Git server under Linux (Server)

- Oracle RMAN repair logical bad blocks (Database)

- CentOS network configuration 7, and set the host name and IP-bound problems (Linux)

- Mount NFS network file system (Linux)

- Ubuntu dual-card system configuration method (Server)

- How to experience Unity 8 Mir on Ubuntu 16.04 (Linux)

- Install Kali Linux via PXE network (Linux)

- Using VMware vSphere Client Linux virtual machine installation CentOS6.4 system (Linux)

- QEMU code analysis: BIOS loading process (Linux)

- 30 minutes with your Quick Start MySQL Tutorial (Database)

- Linux 10 useful examples of command-line completion (Linux)

- Github with .gitignore ignore specified file (Linux)

- Linux package manager - yum (Linux)

- Revised OpenJDK Java Memory Model (Programming)

- Elasticsearch 2.20 Highlight (Server)

- Build their own recursive DNS server (Server)

- Monitor log file (listener.log) (Database)

- Linux, set and view environment variables (Linux)

- To install and deploy Apache under the CentOS (Server)

 
         
  Getting Started with Linux system to learn: how to get the process ID (PID) in the script
     
  Add Date : 2018-11-21      
         
       
         
  Question: I want to know the child shell script running process id. How do I get PID in shell scripts.

When I execute a shell script, it starts a process called sub-shell. As a child of the main shell, the shell sub-shell commands in the script as a batch run (hence the term "batch process").

In some cases, you might want to know to run a sub-shell of PID. The PID information can be used in different situations. For example, you can use the shell script PID create a unique temporary files in / tmp. Sometimes a script needs to detect all running processes, it can exclude itself from the list of processes, sub-shell.

In bash, PID storage sub-shell process in a special variable '$$' in. This variable is read-only, you can not modify it in the script. such as:

#! / Bin / bash
 
echo "PID of this script: $$"
The above script will get the following output:

PID of this script: 6583
In addition to $$, bash shell also export other read-only variables. For example, PPID storage sub-shell parent process ID (that is, the primary shell). UID stored execution of the script of the current user ID. such as:

#! / Bin / bash
 
echo "PID of this script: $$"
echo "PPID of this script: $ PPID"
echo "UID of this script: $ UID"
The output is:

PID of this script: 6686
PPID of this script: 4656
UID of this script: 1000
The above output, PID each execution will change. This because each run will create a new shell. On the other hand, PPID every time as long as you are running in the same shell.

For a list of all bash built-in variables, see man pages.

$ Man bash
     
         
       
         
  More:      
 
- Iptables small summary (Linux)
- Linux (CentOS) SSH login without password authentication (Linux)
- Oracle11g CRS-0184 Problem Solving (Database)
- 4 lvcreate example commonly used commands (Linux)
- Oracle database NUMBER (x, y) data types (Database)
- Graphical interface for the CentOS 6.4 installed and connected by remote VNC (Linux)
- Getting Started with Linux system to learn: how to install the Shrew Soft IPsec VPN on Linux (Linux)
- Linux commands to access the cheat sheet (Linux)
- How to use the Linux command compress JPEG images (Linux)
- Zabbix monitors the status of TCP connections (Server)
- Smack 4.1.x Upgrade Guide (Linux)
- Design and implementation of environment sniffer running under Linux (Linux)
- 11.2.04 Oracle RAC directory crfclust.bdb file is too large, Bug 20186278 (Database)
- C # assembly calls across constants, variables and functions (Programming)
- Linux Kernel 4.2 Installation Instructions (Linux)
- CentOS 7 source code to compile and install Nginx process record (Server)
- impdp error ORA-39001, ORA-39000, ORA-31619 (Database)
- Linux System Getting Started Learning: The Linux logrotate (Linux)
- impdp error ORA-31631, ORA-39122 (Database)
- Linux kernel update error, update-initramfs: failed Solution (Linux)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.