How to find out the user of parent shell inside a child shell?
You can use the $PPID
variable to assist you along with a command or two:
#!/bin/bash
USER=`ps u -p $PPID | awk '{print $1}'|tail -1`
echo $USER
How to find out the user of parent shell inside a child shell?
You can use the $PPID
variable to assist you along with a command or two:
#!/bin/bash
USER=`ps u -p $PPID | awk '{print $1}'|tail -1`
echo $USER
How can I tell if I'm in a child shell
Use the SHLVL
environment variable.
man bash:
SHLVL : Incremented by one each time an instance of bash is started.
$ echo "$SHLV"
1
$ bash
$ echo "$SHLV"
2
$ exit
$ echo "$SHLV"
1
How to tell the parent-child relationship of shell processes?
If all you are given is two process IDs, there is no way to tell which is the parent and which is the child, or if one is even an ancestor of the other. Process IDs are assigned in order as processes are created, using the next largest (modulo 65535) unused ID available at the time.
You can, however, examine the value of PPID
in the shell to see who the parent process is.
bash-4.3$ echo $$
45564
bash-4.3$ bash
bash-4.3$ echo $$
45565
bash-4.3$ echo $PPID
45564
bash-4.3$
How to pass values from child shell to parent shell
This is impossible. The best that can be done is for the child to print the desired assignments, and for the parent to exec
them.
exit from a function in child shell script to parent shell script
You can't specify how many levels "up" to return, but you can respond to the exit status of the call. Just let status
return as it currently does, and since you are sourcing the file, change the call to status
to
status || return
This will cause the sourced script to return to the parent if status
has a non-zero exit status.
How to get child process from parent process
Just use :
pgrep -P $your_process1_pid
Related Topics
List of Available Wireless Networks with Golang (Under Linux)
Pipe Tar Extract into Tar Create
Create and Test X86-64 Elf Executable Shellcode on a Linux Machine
Skip Successfully Downloaded Files Using Wget
Installing Zlib in Linux Server
What Is The Mutex Acquire and Release Order
How to Run 16 Bit Code on 32 Bit Linux
How to Solve Libusb_Error_Busy on Raspberry Pi (Debian) Running Node.Js
Where to Store The Private Key on a Digital Signing Server
Gradle 1.3: Build.Gradle Not Building Classes
Sending Mail in Bash Script Outputs Literal \N Instead of a New Line
Linux Mail Adding Content Type Headers Not Working
How Convert Address in Elf to Physical Address
How to Detect Whether Tomcat and Ant Are Installed on Linux Machine
Why Does The Same Executable Use Different Runpaths for Different Library Lookups
How to Solve Ssh: /Usr/Lib64/Libcrypto.So.10: No Version Information Available