-
-
Save yuhr123/4e7a09653e833a083dae87ba76b7d642 to your computer and use it in GitHub Desktop.
A Bash script is used to obtain command line parameters of the running programs.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check whether the command line parameters are provided. | |
# If not, display the usage and exit | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <process_name>" | |
exit 1 | |
fi | |
# Get the process name to find from the command line parameters | |
process_name="$1" | |
# Use PGREP to find all the matching PIDs, | |
# and check the command line parameters one by one | |
for pid in $(pgrep $process_name); do | |
cmdline=$(cat /proc/$pid/cmdline 2>/dev/null | tr '\0' ' ') | |
if [ -n "$cmdline" ]; then | |
echo "PID: $pid, Command Line: $cmdline" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment