I have a service on Ubuntu which elevate new process using sudo command and then call bash script XY.
From this bash script XY I need to find process id of the service which called the process.
Parent process id ($$) does not work, probably because sudo elevation.
CodePudding user response:
Try this test.sh
#!/bin/bash
ps -ef | awk '$2 == "'$PPID'" { print $3 }'
Run it with :
$ chmod x test.sh
$ sudo ./test.sh
$ echo "Sudo should print $$."