Hacker News new | past | comments | ask | show | jobs | submit login

Why not ctrl+c, then arrow up and enter? If the command can't be stopped even for a few milliseconds then there is something wrong with it.



I didn't want to send any signal - because I could not remember what I had done, and was afraid for sideeffects (I did remember that the logic had to do with database actions).

I wanted to see the command without "messing" with the execution in any way - after all, it was running fine for 6 months, why interrupt it (and face potential effort in fixing messed up state) if I could see the command "from the outside"?

And that I did :-)


C-z is actually your friend here. I've never ever seen SIGSTOP affect anything negatively. I even SIGSTOP Mac OS X apps sometimes. They just beachball until you SIGCONT them, then they happily continue, oblivious.

If you're worried about timing out of the process being unresponsive, just C-z and then "bg" real quick. Then you can up arrow at your leisure and "fg" when you've copied the command away...


Try doing the Ctrl-z/fg sequence in this: "while true ; do sleep 1 ; done". Under Linux at least, you'll see that after 'fg', the loop ends :-(

Apparently C-z followed by fg is not bulletproof...


Thats an interesting example.

zsh does the right thing, when you bg it back it recovers the loop as it was. Bash seems to forget about the loop and only recovers the "sleep 1", when it starts executing again it sleeps 1 and exits.

If you want to make sure it will work you should wrap it around another bash:

    bash -c 'while true ; do sleep 1 ; done'
should work fine.


Parens work too:

   (while true ; do sleep 1 ; done)


I tried it, and you're right - but why does this happen?


while, true, do, done are all [bash] shell builtins. They are not running processes that can be suspended.

sleep(1) is the only process that can be suspended in this command. When you "fg", the suspended sleep(1) is signaled, and resumes. And then it exits.

When you do this in a subshell (in parens), you suspend/resume the subshell in its entirety, which capture the loop construct.

Why does it work in zsh?!


Warning: Ctrl-Z sends SIGTSTP, not SIGSTOP. SIGTSTP can be caught by programs, while SIGSTOP cannot.


There was a realllly old OS X program that would automate this so the front-most app was the only one running, to speed up your machine.


Don’t know which old OS X program you’re talking about, but there are actually modern OS X programs which also do this. App Tamer¹, for example.

――――――

¹ — http://www.stclairsoft.com/AppTamer/index.html


I know a lot of programs that would have issues with Ctrl-C - I understand why the OP didn't want to do this.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: