Sorry for this color screen shot but I think it helps highlight the problem better than copy & paste + code format:
Here is the same screen in code format:
───────────────────────────────────────────────────────────────────────────────
rick@dell:~$ ps a | grep display-
26457 pts/2 S+ 0:00 grep --color=auto display-
───────────────────────────────────────────────────────────────────────────────
rick@dell:~$ ps a | grep display-
28927 pts/18 S+ 0:00 sudo /usr/local/bin/display-auto-brightness
29174 pts/18 S+ 0:00 /bin/bash /usr/local/bin/display-auto-brightness
30183 pts/2 S+ 0:00 grep --color=auto display-
───────────────────────────────────────────────────────────────────────────────
rick@dell:~$ pstree | grep display-
|-cron---cron---sh---display-auto-br---sleep
| | | | |-bash---sudo---display-auto-br---sleep
───────────────────────────────────────────────────────────────────────────────
rick@dell:~$ ps a | grep cron
16031 pts/2 S+ 0:00 grep --color=auto cron
───────────────────────────────────────────────────────────────────────────────
rick@dell:~$ ps a | grep display
26773 pts/2 S+ 0:00 grep --color=auto display
28927 pts/18 S+ 0:00 sudo /usr/local/bin/display-auto-brightness
29174 pts/18 S+ 0:00 /bin/bash /usr/local/bin/display-auto-brightness
───────────────────────────────────────────────────────────────────────────────
This morning after reboot the cron job - /etc/cron.d/display-auto-brightness
should have started up. I thought it never started on it's on based on the first section.
I manually started the script with sudo /usr/local/bin/display-auto-brightness
. The second section shows how ps
returns two process ID's for the single job. Oncefor the sudo
elevation that started the job and the second for the script itself.
Is there a programmatic way of identifying these two PIDs as one job? The reason being the next development step is when resuming from suspend to see if the single job (not two processes) are already running and kill it when starting the same job again. This will give instant display brightness adjustment if resuming in daylight after suspending in darkness or vice versa.
In the third section I used the pstree
command and discovered the cron job that didn't appear with ps
command is showing here. Why is that?.
In the fourth section I pipe ps
output through grep
using cron
as filter and nothing shows up. Why is that?
In the fifth and final section I repeat the second section ps a | grep display-
to reaffirm previous findings.
Edit 1
I think I've figured out why the fourth section doesn't show cron
running. It's because of normal user status whilst cron is running as root. The solution is to use:
$ sudo ps aux | grep cron
root 1122 0.0 0.0 29008 2936 ? Ss 04:16 0:00 /usr/sbin/cron -f
rick 7273 0.0 0.0 14224 1028 pts/2 S+ 17:50 0:00 grep --color=auto cron
Now we can see the original reboot at 4:16am is still running under cron job. Process ID 1122 might be the one that needs to be killed when resuming from suspend in future program changes. This still doesn't tie into the script name display-auto-brightness
which pstree
command finds.
Edit 2 Windows Subsystem for Linux desktop shortcut
When setting up an icon to call a bash script from Windows 10 desktop you get more running programs than under plain Ubuntu 16.04 and Unity:
$ ps -ef | grep lock-screen
rick 29243 29242 0 17:13 tty1 00:00:00 /bin/bash -c cd && DISPLAY=0:0 /mnt/e/bin/lock-screen-timer
rick 29244 29243 0 17:13 tty1 00:00:00 /bin/bash /mnt/e/bin/lock-screen-timer
When you use pstree
there are even more PID's:
$ pstree -gp | grep lock-screen
|-init(29242,29242)---bash(29243,29242)---lock-screen-tim(29244,29242)---sleep(29777,29242)
In the "old" method I would kill lock-screen-timer
"29244". Looking at ps -aux
I think I should kill "29243". Looking at pstree
though the init
parent process should be killed which is "29242".
Further testing reveals you can't kill init
PID
This screen shot shows how you can't kill init
PID directly. You can kill it's child which causes it to die, but the grandchild and great-grandchild keep running. It would appear you need to kill three PID's under Windows 10 WSL when a desktop shortcut is used:
rick@alien:/mnt/c/Windows/System32$ pstree -gp | grep lock-screen
|-init(30554,30554)---bash(30555,30554)---lock-screen-tim(30556,30554)---sleep(30587,30554)
rick@alien:/mnt/c/Windows/System32$ kill 30554
-bash: kill: (30554) - Operation not permitted
rick@alien:/mnt/c/Windows/System32$ sudo kill 30554
[sudo] password for rick:
rick@alien:/mnt/c/Windows/System32$ pstree -gp | grep lock-screen
|-init(30554,30554)---bash(30555,30554)---lock-screen-tim(30556,30554)---sleep(30587,30554)
rick@alien:/mnt/c/Windows/System32$ kill 30555
rick@alien:/mnt/c/Windows/System32$ pstree -gp | grep lock-screen
|-lock-screen-tim(30556,30554)---sleep(30612,30554)
rick@alien:/mnt/c/Windows/System32$ pstree -gp | grep sleep
|-lock-screen-tim(30556,30554)---sleep(30633,30554)
rick@alien:/mnt/c/Windows/System32$ kill 30556
rick@alien:/mnt/c/Windows/System32$ pstree -gp | grep sleep
`-sleep(30633,30554)
rick@alien:/mnt/c/Windows/System32$ kill 30633