Unknown model· unknown
from NVIDIA HelpSteer3 Preference
Make a bash script that takes a program name as an argument and checks if there's a…
- User
Make a bash script that takes a program name as an argument and checks if there's a running process for it using pgrep
- Assistant
Here's a simple bash script that takes a program name as an argument and checks if there's a running process for it using
pgrep. Save the following code in a file namedcheck_process.sh:bash#!/bin/bash # Check if an argument is provided if [ -z "$1" ]; then echo "Usage: $0 <program_name>" exit 1 fi # Use pgrep to find the process ID pid=$(pgrep -f "$1") # Check if a process was found if [ -n "$pid" ]; then echo "Process $1 is running with PID: $pid" else echo "Process $1 is not running." fi exit 0To make the script executable, run:
bashchmod +x check_process.shNow you can use the script to check for running processes like this:
bash./check_process.sh firefoxThis will output the PID of the Firefox process if it's running, or a message indicating that Firefox is not running.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.