Skip to main content
2 of 2
added 184 characters in body
Stéphane Chazelas
  • 586.4k
  • 96
  • 1.1k
  • 1.7k

As you clarified in comments it's still running in foreground on an interactive shell, you should just be able to press Ctrl+Z.

That will suspend the ./command job. Unless ./command actually intercepts the SIGTSTP signal and chooses to exit(0) in that case (unlikely), the exit status will be non-0 (128+SIGTSTP, generally 148), so sudo poweroff will not be run.

Then, you can resume ./command in foreground or background with fg or bg.

You can test with:

sleep 10 && echo poweroff 

And see that poweroff is not output when you press Ctrl+Z and resume later with fg/bg.

Or with

sleep 10 || echo "failed: $?" 

And see failed: 148 as soon as you press Ctrl+Z.

Note that this is valid for zsh and assuming you started it with ./command && sudo poweroff. It may not be valid for other shells, and would not be if you started it some other way such as (./command && sudo poweroff) in a subshell or { ./command && sudo poweroff; } as part of a compound command (which zsh, contrary to most other shells transforms to a subshell so it can be resumed as a whole when suspended).

Stéphane Chazelas
  • 586.4k
  • 96
  • 1.1k
  • 1.7k