Bash: add a comment to command line options

I have an RHEL machine in which I run many processes. Many processes can have equivalent initial parameters, therefore from topand psthey are identical in this category and cannot be identified from each other.

How can I name or mark a process in my parameters so that I can identify one from the other? Other than that in bash, how do I do this for a Java process or session session?

+5
source share
5 answers

If this is specific to java, you can pass an unused system property as follows:

java -Dtag=process1  -jar ....

This is not only displayed on the command line, but also visible inside the process if you need it.

+1

- $!. , , , . :

gedit & gedit1=$!

gedit gedit1. .

kill $gedit1
+6

script,

#! /bin/bash
"$@"

, process-label.

$ ln process-label other-label

$ process-label sleep 1800 &
$ other-label sleep 800 &

15016 ttys002    0:00.00 /bin/bash ./process-label sleep 1800
15017 ttys002    0:00.00 sleep 1800
15021 ttys002    0:00.00 /bin/bash ./other-label sleep 800
15022 ttys002    0:00.00 sleep 800
+1
0

, , ( ) java .

:

:

$ cd /tmp
$ ln -s /bin/cat abc
$ ln -s /bin/cat def
$ ./abc

:

$ cd /tmp
$ ./def

:

$ ps aux | egrep 'abc\|def'

You will see one process with the name "abc" and one with the name "def", as well as the name "cat". Therefore, if you do this by creating a different link for each of the processes, you can distinguish them.

0
source

All Articles