Process

proc_running

Return 0 if a process with the given name is currently running. Uses pgrep when available, falls back to ps | grep.

Example

proc_running sshd    # 0 if sshd is running

Arguments

  • $1 (string): Process name or pattern

Exit codes

  • 0: Running; 1 Not running

proc_alive

Return 0 if a PID is alive (process exists).

Arguments

  • $1 (int): PID to test

Exit codes

  • 0: PID alive; 1 PID not found

proc_stop

Stop a process by PID gracefully. Sends SIGTERM, waits up to $2 seconds (default 10), then sends SIGKILL.

Arguments

  • $1 (int): PID to stop
  • $2 (int): Grace period in seconds before SIGKILL (default: 10)

Exit codes

  • 0: Process stopped; 1 PID not found initially

proc_pids_matching

List PIDs for processes whose command line matches a pattern. One PID per line. Excludes the current process and grep itself.

Example

proc_pids_matching nginx    # prints each nginx worker PID

Arguments

  • $1 (string): Pattern to match against full command line

Exit codes

  • 0: At least one match; 1 No matches

Output on stdout

  • PID list, one per line

proc_parent

Get the parent PID of a given PID.

Arguments

  • $1 (int): PID (default: $$)

Exit codes

  • 0: Always; 1 PID not found

Output on stdout

  • Parent PID

proc_grep

Show full ps output for processes matching a pattern. Like pgrep but shows the full process table row. Prints the header line followed by matching rows. Uses the [x]yyy bracket trick so the awk process never matches itself: searching for "nginx" becomes the awk pattern "[n]ginx", which matches "nginx" in ps output but not the literal string "[n]ginx" in awk's own command line.

Example

proc_grep nginx
proc_grep sshd

Arguments

  • $1 (string): Pattern to search for

Exit codes

  • 0: At least one match; 1 No matches

Output on stdout

  • ps header + matching process rows

proc_children

List the PIDs of all direct child processes of a given parent PID. Uses pgrep if available, otherwise falls back to parsing 'ps -e'.

Arguments

  • $1 (int): Parent PID to query (default: $$)

Exit codes

  • 0: Always

Output on stdout

  • One PID per line