-1

enter image description here

  • I have 3 java process running on my host - i access the host by a ssh client. Some one of that process freezed and i need kill that pid process to re-start it
  • I know the name of the file, but i dont know the number of the file.
  • That process is running inside of a screen. If i join on the screen the java process is opoenned, running and i cant stop it by command or ctrl+c cause its freezed. The unique solution i see is killing it.
[root@vmi1478348 ~]# screen -ls There are screens on: 18043.lob (Detached) 10196.fac (Detached) 10100.hu3 (Detached) 9868.bung (Detached) 
  • That pid number are not the same process pid numbers, probally are the screen pid numbers. So if you kill it, you will not kill the java process you want to kill, killing the screen.

  • Usin ps aux command i can check the pids, but the name of the java file is on the end of the line of the java process and it not show on ssh client console screen like picture. I already try reduce font size and the problem still, it not show the rest of the line, already try select the line with the mouse to copy on notepad and it still cut it. Any solution ?

1

3 Answers 3

2

All you need is pgrep:

pgrep -fa 'file\.jar' 
  • -f: forces pgrep to match the extended regular expression against the full invocation command-line¹ which will include the filename.
  • -a: forces pgrep to output the full invocation command-line (which will include the filename), auto-folding lines exceeding the terminal's width.

By doing this, you'll get a list of process IDs matching the expression, along with their full invocation command-line, with each entry nicely folding onto multiple lines if needed.

At that point, you can just kill the right pid, or pass the same regexp to pkill -f instead of pgrep -fa (if using the second method, make sure you only have your target process on the list produced by pgrep -fa 'file\.jar' as that will signal all processes matching the regular expression file\.jar).


Another way: if available, you can just use htop and scroll to the right using arrow keys.


Another possible way: I'm pretty sure signaling the screen process correctly will also enforce propagation and consequently termination to the child. I'll maybe figure this out and report back, I'm kinda rusty on this topic.


¹ Technically, with current versions of the procps implementation of pgrep on Linux-based systems at least, that's the concatenation with spaces of the arguments passed to the last execve() system call that the process (or any of its ancestors) made, with some escaping of some characters, and truncated to 128KiB, the same thing as reported by procps' ps -wwo args= for the pid.

2

If you want to see more of the command line, with many ps implementations including that from procps¹ on Linux, you can just add the -w option (or w with the BSD-style API you're using), twice to get the full command line²:

ps auxww # BSD-style ps -Afww # standard style 

procps' ps also has a -C option to report processes running a given command (using heuristics), so you can do:

ps -fwwC java 

To list the full command lines of java processes.

On GNU/Linux, to reliably find processes that have file.jar as one of the arguments passed to the command it (or its ancestor) executed, you can do:

grep -lFzx file.jar /proc/*/cmdline 

(lists the files that have at least one zero-delimited record that matches file.jar as a Fixed string and exactly (not as a substring)).

Or to limit it to processes running /usr/bin/java:

find /proc -maxdepth 2 \ -name cmdline \ -execdir test exe -ef /usr/bin/java ';' \ -exec grep -lFzx file.jar {} + 

Or shorter and more efficient with the zsh shell:

print -rC1 /proc/<2->(e[$' [[ $REPLY/exe -ef /usr/bin/java && \0$(<$REPLY/cmdline) = *\0file.jar\0* ]] ']:t) 

(replace print -rC1 with kill to kill those processes).

With that approach, you can make the selection stricter by selecting only those processes that have file.jar as the next argument after a -jar one by changing the pattern to *\0-jar\0file.jar\0*.

Using pkill as suggested by @kos is probably good enough though and can be made stricter with:

pkill -f '^java (.* )?-jar file\.jar( |$)' 

It's not as reliable as:

  • it doesn't check what executable is being run, just the arguments that are passed to it.
  • it could run into the 128KiB limit (and for instance match on a command line that has -jar file.jarringly.unlikely.jar at the end of an extremely long java command line)
  • as arguments are joined with spaces we lose the information of where each starts and ends, so it could match on a process that was started with 'java and lambada' -f 'jam -jar file.jar' for instance.
  • it will fail if there are byte sequences in the command line that can't be decoded into characters in the locale's encoding.

All of which are extremely unlikely.


¹ The most commonly used one on non-embedded operating systems using Linux as their kernel.

² still limited to 128KiB with the ps from procps, and beware that older versions of Linux only exposed the first 4KiB of the command line (argument list) in /proc/<pid>/cmdline where ps gets the information from.

1
  • I'm not strongly suggesting pkill anymore, because you (rightfully so in general, and by the way it was also unintended to suggest pkill in that specific instance, I just got confused and I actually meant to suggest kill) removed it from my answer and added that option as an alternate one; I second not pkilling processes in general unless you actually mean to kill more than one process, otherwise I see no reason to not just kill the right PID. Thank you for your edits and for the added insights. Commented Apr 15, 2024 at 8:37
0

not a good solution but solve part of the problem edit config of ssh client and change font size to 1

insane solution enter image description here

you cant read anything but selection the most long lines and copying on a notepad i found the line:

root 12868 19.2 8.4 5963840 1381788 pts/1 Sl+ 15:45 3:39 java --illegal-access=permit -Duser.timezone=America/Sao_Paulo -Dlog4j2.formatMsgNoLookups=true -Xms1G -Xmx1G -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -XX:+AlwaysPreTouch -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -XX:G1HeapWastePercent=5 -XX:G1MixedGCCountTarget=4 -XX:InitiatingHeapOccupancyPercent=15 -XX:G1MixedGCLiveThresholdPercent=90 -XX:G1RSetUpdatingPauseTimePercent=5 -XX:SurvivorRatio=32 -XX:+PerfDisableSharedMem -XX:MaxTenuringThreshold=1 -Dusing.aikars.flags=https://mcflags.emc.gs/ -Daikars.new.flags=true -jar bung.jar nogui

  • the name of the process i want is bung.jar and now i know the pid 12868
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.