I tried running a script using nohup like,
nohup script.sh &
When I tried
ps -ef | grep "script.sh"
I couldn't find it there except for the grep which is being run with that string as a parameter.
Am I doing it right?. Does this mean that the process has indeed finished execution? Thanks.
If you see the name of your process/program among those listed then it hasn't finished yet. To check the results or status of the programs, log back in to the same server. Once the job has finished its output will be contained in a file located within your home space. The filename will be "nohup.
Run ping command with nohup command. Re-open the terminal and run pgrep command again. You will get the list of the process with process id which is running. You can stop any background process by running kill command.
You cannot exactly get a list of commands started with nohup but you can see them along with your other processes by using the command ps x . Commands started with nohup will have a question mark in the TTY column.
Open Task Manager and go to Details tab. If a VBScript or JScript is running, the process wscript.exe or cscript.exe would appear in the list. Right-click on the column header and enable "Command Line". This should tell you which script file is being executed.
At the beginning of your shell script, write the PID to a file (for example, in /var/run). Then, you can just search for that PID to know if the process is done or not. You can get the PID of your shell script using the built-in $$
variable.
To record the PID, put at the top of your script:
echo $$ > /var/run/myscript.pid
Then, to check if it's still running:
ps -p `cat /var/run/myscript.pid`
You might not be able to write into /var/run
as a normal user. If not, just use /tmp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With