Home PC Games 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     - Solve ORA-01012: not logged on (Database)

- Sysdig: system troubleshooting tool (Linux)

- Using Oracle for Oracle GoldenGate to achieve a one-way data synchronization (Database)

- Shell generated using automated configuration script Orabbix (Database)

- Using nmcli commands to manage network in RedHat / CentOS 7.x (Linux)

- Servlet life cycle works (Programming)

- Repair fatal error in Linux: lame / lame.h: No such file or dir Error (Linux)

- C ++ input and output summary _ Input (Programming)

- Linux, Google Test (GTest) test environment to build step (Linux)

- OpenSUSE installation on CentOS6 (GUI) (Linux)

- numpy and SciPy installation under Python for scientific computing package (Linux)

- iOS Sensor Development - add to APP phone password, fingerprint security authentication (Programming)

- Linux, set and view environment variables (Linux)

- Grading defense against Linux server attacks (Linux)

- CentOS 6.5 system installation Oracle11.2.0.4 basic steps (Database)

- Google open source TCP team repaired the Linux kernel TCP flaw (Linux)

- Example of use WebSocket (Programming)

- Linux memory management (Linux)

- SLF4J Tutorial (Programming)

- Redis 3.0.3 Cluster Setup (Database)

 
         
  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:      
 
- VMware ghost Linux card error (Linux)
- Hadoop 2.7.1 installation configuration based on availability QJM (Server)
- Fedora10 use Git version Configuration Management (Linux)
- RedHat Linux 6 desktop installation (Linux)
- OpenSSL: implementation creates a private CA, certificate signing request Explanation (Server)
- Oracle 12C modify spfile path (Database)
- xargs Detailed description (Linux)
- Use nice, cpulimit and cgroups limit cpu usage (Linux)
- Linux see whether there is a hacker program (Linux)
- JavaScript file loader LABjs API Explanation (Programming)
- Gentoo: startx problem appears Failed to load module (Linux)
- ORA-12547: TNS: lost contact error Solution (Database)
- C language keywords Comments (Programming)
- Two classic macro definition under Linux (Linux)
- Ubuntu users to install Xtreme Download Manager (Linux)
- Installation through the network Debian 7 (Wheezy) (Linux)
- Linux Getting Started tutorial: Experience VirtualBox Virtual Machine chapter (Linux)
- Encrypted with GnuPG signature to verify the authenticity and integrity of downloaded file (Linux)
- Brief Linux commands (Linux)
- Oracle database with test data insertion speed (Database)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.