0

I have a bash script which is run via at, I run it like echo "bash /path/to/my/script.sh" | at -M now because I want it to run detached.

When the script is spawned, immediately I see 2 instances (ps), and even after my script completes successfully, another instance just wont terminate. It will get reparented to pid 1 and just keeps doing wait ( strace shows wait4(-1...).

I am not able to figure out why or how this second instance is forked! When I run the script without at, I don't see the second process. Any hints/tips to debug this ?

Thanks.

1 Answer 1

0

checkout this simple script:

#!/bin/bash exec >/tmp/$$.log exec 2>/tmp/$$-2.log set -x echo "1" echo "2" >&2 

This will redirect the whole output of the scripts stdout & stderr to the specified log files (in this case, /tmp/<pid>.log and /tmp/<pid>-2.log) and the stderr part of the logfile will contain each command it executes. You can use this output to follow the execution of the script and see, where it hangs...

content of 17958-2.log :

+ echo 1 + echo 2 2 
1
  • Thanks, I have already added a tracing logic with exec 4 > log.trace; BASH_XTRACEFD=4 ; set -x but the child process logs are not seen here or are getting overlapped! I will try to use the pid in log name. Commented Jul 28, 2020 at 3:12

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.