Skip to content

Commit

Permalink
Validate the input value of -pid. (#2061)
Browse files Browse the repository at this point in the history
Make sure that the pid exists before running the `perf` command.

Co-authored-by: Brian Robbins <brianrob@linux.microsoft.com>
  • Loading branch information
brianrob and Brian Robbins authored Jul 15, 2024
1 parent 810102e commit f68d871
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/perfcollect/perfcollect
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,13 @@ BuildPerfRecordArgs()
# Filter to a single process if desired
if [ "$collectionPid" != "" ]
then
collectionArgs="$collectionArgs --pid=$collectionPid"
if ps -p "$collectionPid" > /dev/null;
then
collectionArgs="$collectionArgs --pid=$collectionPid"
else
WriteWarning "Process with PID '$collectionPid' does not exist. Please specify a valid PID."
exit 1
fi
else
collectionArgs="$collectionArgs -a"
fi
Expand Down

0 comments on commit f68d871

Please sign in to comment.