0

I am executing a command using timeout in the following way that waits for seconds and then exits

timeout -k 1 10 <command> &> error.log & disown %

However, I've realized that since this is a single command; it would not be possible to get the exit status code from the timeout command. I would like the get the exit status code from the timeout command to output verbose messages. I have searched this forum and was unable to figure out a solution.

Is there someway to get both the exit status code first and then disown it?

UPDATE:

The reason I disown is because I do not want the "Terminated message" to be displayed in the console.

line 106:  5777 Killed                  timeout -k 1 10 <command>

I want my script to terminate the command after a certain time. If the command executes in less than threshold; the script continues; else, the script is exited.

2
  • The exit status reported when starting a background task is always zero. The exit status of your command would be available to the shell that started the command if it used wait on the command's PID or job ID, but not until it terminates (for obvious reasons, it's the exit status). Please clarify what it is you want to achieve.
    – Kusalananda
    Commented Apr 18, 2020 at 7:21
  • updated comment!
    – user782400
    Commented Apr 19, 2020 at 22:48

1 Answer 1

1

When a command exits and sends a code, there won't be anything left to be disowned. You could try to supplement the command with something to write the exit code to disk, and then background and disown the entire list.

1
  • updated comment!
    – user782400
    Commented Apr 19, 2020 at 22:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .