2

I'm using the openjdk:17 docker image, the os is Oracle Linux Server v8.5. I ssh into the container with root user and found almost all common commands are not available. I have tried ps, pidof etc but getting command not found error. I'm trying to add a preStop hook to kill the java process gracefully but need a command to find the java process. Any idea how to achieve this?

Here is the output of ls -l /proc/*/exe. There sees to be a number of pid associated to the java process, but I'm sure I only have one. What is the clear way to find the pid and kill it? one liner is preferred

lrwxrwxrwx 1 root root 0 Mar  3 16:45 /proc/1/exe -> /usr/java/openjdk-17/bin/java
lrwxrwxrwx 1 root root 0 Mar  3 20:35 /proc/106/exe -> /usr/bin/bash
lrwxrwxrwx 1 root root 0 Mar  3 20:45 /proc/164/exe -> /usr/java/openjdk-17/bin/jshell
lrwxrwxrwx 1 root root 0 Mar  3 20:45 /proc/185/exe -> /usr/java/openjdk-17/bin/java
lrwxrwxrwx 1 root root 0 Mar  3 21:15 /proc/self/exe -> /usr/bin/coreutils
lrwxrwxrwx 1 root root 0 Mar  3 21:15 /proc/thread-self/exe -> /usr/bin/coreutils
user3908406
  • 1,416
  • 1
  • 18
  • 32
  • How about `ls /proc`? – Andreas Mar 03 '22 at 21:06
  • this command works and show me a list files – user3908406 Mar 03 '22 at 21:07
  • The directory /proc contains (among other things) one subdirectory for each process running on the system, which is named after the process ID (PID). https://www.kernel.org/doc/html/latest/filesystems/proc.html In your container are most likely only one or two running processes, nvaigate to /proc/1 and `cat cmdline` to see which process has this pid. – Andreas Mar 03 '22 at 21:08
  • 1
    Or even simpler `ls -l /proc/*/exe`. – Andreas Mar 03 '22 at 21:13
  • Thanks @Andreas, I just updated the description with the output, would you take a look? – user3908406 Mar 03 '22 at 21:17
  • 2
    It's always PID 1, most likely this is also the `CMD` you used in your Dockerfile? Btw. if you are not forced to use the oracle linux version simply use a debian based image: `openjdk:17-slim-bullseye`. – Andreas Mar 03 '22 at 21:25
  • yes, this is the my `CMD` – user3908406 Mar 03 '22 at 21:26

0 Answers0