Search code examples
linuxbashsshpidnohup

Get PID of the jobs submitted by nohup in Linux


I'm using nohup to submit jobs in background in the machines I got through BSUB and ssh.

My primary machine is on RHEL, from there I am picking up other AIX machine by BSUB(Submits a job to LSF) and also doing a SSH login to another server. After getting these two machines, executing a script(inner.sh) there through nohup.

I'm capturing the respective PIDs through echo $$ in the script which I am executing(inner.sh). After submitting the nohup execution in background, I am exiting both of the machines and landing back to primary RHEL machine.

Now, from this RHEL machine, I'm trying to get the status of the nohup execution by ps -p PID with the help of the previously captured two PIDs, but not getting any process listed.

Top level wrapper script wrapper.sh:

#!/bin/bash

#login to a remote server
ssh -k xyz@abc < env_setup.sh

#picking up a AIX machine form LSF
bsub -q night -Is ksh -i env_setup.sh

ps -p process-<AIX_machine>.pid
#got no output
ps -p process-<server_machine>.pid
#got no output

Script passed to Machines picked up by BSUB/SSH to execute nohup env_setup.sh:

#!/bin/bash
nohup sh /path/to/dir/inner.sh > /path/to/dir/log-<hostname>.out &
exit

The actual script which I am trying to execute in machines picked up by BSUB/SSH inner.sh:

#!/bin/bash
echo $$ > /path/to/dir/process-<hostname>.pid
#hope this would give correct us the PID of the remote machine
#execute some other commands

Now, I am getting two process-<hostname>.pid files updated with two PIDs respectively each for both of the machines.

But ps -p at wrapper script is giving us no output.

I am picking up the process IDs from remote machines and doing ps -p at my local RHEL machine.

Is it the reason I am not getting any status update of those two processes?

Can I do anything else to get the status?


Solution

  • ps give the status of local processes. bsub can be used to get the status of processes on each remote machine.