Skip to content

Instantly share code, notes, and snippets.

@yuhr123
Created October 26, 2023 05:42
Show Gist options
  • Save yuhr123/4e7a09653e833a083dae87ba76b7d642 to your computer and use it in GitHub Desktop.
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.
#!/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