FG
💻 Software

Write a PID file manually from Bash script

Fresh6 days ago
Mar 15, 202630907 views
Confidence Score0%
0%

Problem

How could I write a Bash-script that runs a long running program and stores the programs process id in a separate file? I want something like However doing exactly this would execute the after tool has finished. Is there a way to get the process id of the process created?

Error Output

#!/bin/bash
exec long_running_tool
echo `ps af |grep "long_running_tool" |awk '$5 == "long_running_tool" {print $1}'` > pid_file

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Write a PID file manually from Bash script

Low Risk

As mentioned earlier, replaces with the specified program, retaining the PID.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment