7 ms·
This is nice! On OSX, processes can be paused and continued too (by name via killall, and by PID via kill): kill -STOP 1234 kill -CONT 1234 killall -STO
by tomkinstinch 11y ago
This is nice! On OSX, processes can be paused and continued too (by name via killall, and by PID via kill):
kill -STOP 1234
kill -CONT 1234
killall -STOP -c "Pandora"
killall -CONT -c "Pandora"
A more nuanced control is to throttle down the CPU, via cputhrottle[1].
If I'm running a CPU-intensive calculation and don't want to bog down the rest of my system I will use it to give me enough cycles for Sublime Text to work smoothly.
It's easy to call:
sudo cputhrottle PID cpuUsage%
ex.
sudo cputhrottle 12345 400
1. http://www.willnolan.com/cputhrottle/cputhrottle.html http://www.willnolan.com/cputhrottle/cputhrottle.html
- archagon 11y agoI actually wrote a little GUI app to do this for me a while back! It works but the UI is a bit broken. Maybe somebody will find it useful. https://github.com/archagon/app-pauser https://github.com/archagon/app-pauser
- ars 11y agoOn debian the program is cpulimit.
- jokr004 11y agoThe kill -STOP command works on linux too
- ars 11y agoIt does, but cpulimit repeatedly stops/continues the program to keep it within a certain amount of CPU. It works pretty good, but I have had flash games crash if you limit them too low for a while.
- jokr004 11y agoOk I had a total brain-fart there.. I didn't realize that you were responding about the cputhrottle command. Whoops
- leni536 11y agoI think using nice or renice is better practice. Hard throttling is way more inefficient.
- curun1r 11y agoIt may be, but it doesn't solve some of the problems that cputhrottle does. My main use for cputhrottle is to limit the CPU usage of Flash. It's not that I want to use the CPU for something else, at least not at the moment, but I don't want my laptop's fans to turn on, the whole thing to heat up and it to kill my battery life. [re]nice will only allow another process to get CPU priority, it won't keep the CPU utilization low. The bizarre part, when it comes to Flash, is that I've yet to see an actual difference in the application behavior when I throttle down it's CPU usage. I would think that if it normally maxes out 7 of my 8 logical cores, being limited to 40% of one core would make introduce slowness. But I guess that's just an indication of how poorly written the OS X flash client it.
- dx211 11y agoYou might not notice the difference, but that guy at Apple who's only getting 5% of his usual haul of bitcoins this month sure will!
- anom9999 11y agoOnly yesterday I was raging at Flash for continually chewing up my CPU and RAM. I hadn't even considered setting limits on the processes. So thank you for the suggestion.
- tehwalrus 11y agoFlash is running an event engine like JS under there. Your comment made it occur to me that they might busywait, rather than having a proper scheduler. This seems insanely lazy.
- ars 11y agoIt's not a busywait, they use the extra CPU to render additional animation frames. But half the time the difference is not visible anyway.
- vezzy-fnord 11y agoSIGSTOP and SIGCONT are generic Unix signals. Where it gets more interesting is using elaborate checkpoint/restore [1] mechanisms for processes to serialize their state (open fds, watches, IPC, etc.) into an image that can then be overlayed, remotely executed, debugged and so forth. [1] https://en.wikipedia.org/wiki/Application_checkpointing https://en.wikipedia.org/wiki/Application_checkpointing
- derefr 11y agoI've always thought this was a wrongheaded solution. I mean, of course, we have these apps that splay themselves all over global system resources in complex ways, and so we need to track down how they've done that, record it, and then replay it later to restore them. It's necessary. But imagine a well-behaved classical X11 app, running in something like a VM or Docker container. You execute its launcher, the VM spins up in the background, the app launches in the VM, and the app's X11 client connects to the X11 server you're staring at and displays things. If we truly want to sandbox apps, wouldn't it make more sense to move more toward a model like that—one where you have a discrete "application backend process" running in a sandbox, and you can just chuck around the sandbox itself willy-nilly (freezing it, thawing it, copying it, etc.) because it has well-defined connection-points to the host?
- vezzy-fnord 11y agoThe purpose of C/R isn't sandboxing, it has nothing to do with it. It's about managing internal state and data structures from an external agent. C/R enables complete persistence by duplicating a process from its image, which can cut initialization and startup times by orders of magnitude, and resume service from an exact position with zero downtime, and not just basic mechanisms like socket superservers. It lets you back up process state at any arbitrary moment, send it over the network, recalculate and reexec immediately and then thaw again for debugging it from that particular point. It just helps enable live migrations and zero downtime recoordinations with far less complicated redundancy schemes. This includes containers. On top of it being a universal save/pause button. Depending on the robustness of the image format, it can be made space efficient through deduplication. C/R is quite invaluable for any scenario that involves fault tolerance, high response times, tracking down difficult bugs, low startup overhead and so on. I'm surprised why it's still such an obscure technique. Besides, I don't think the primary use case here is even graphical apps (not that they don't work just fine). What you really want is a local indexed copy of all the execution environment details, like pipes, sockets, timers, ttys, timers, sigmasks, *fds, etc. for infrastructure.
- rsync 11y ago"This is nice! On OSX, processes can be paused and continued too" Every once in a while I am reminded how wonderful, and perhaps unlikely, it is that I have a nice, slick, mass market consumer device (apple computer running OS X) that is honest to god UNIX underneath. And then sad, knowing that this is a brief golden age that will probably pass.
- arthurcolle 11y agoDon't say that... why would Apple change the underlyings of OS X? Blasphemy :(
- schiffern 11y agoThe precedent is already set. iOS is underlain by the same components, but the end user has no access. We have also seen an incremental approach in the gradual replacement of open APIs/components with closed ones.
- tadfisher 11y agoThey will when it conflicts with their business model. Witness protected access to media keys and the Notification Center.
- bbcbasic 11y agoDon't worry. Linux is slicker.
- vonklaus 11y agoAs someone who just switched to Linux from OS X, it is really hard to migrate. I miss the subtleties of the apple ecosystem. Sure Linux is awesome, but I have been battling trackpad support issues, keymapping the super_key to CMD, and just general battling the UX. tl;dr a more powerful operating system with worse UI, which is the obvious trade. A less powerful system with a fantastic UI.
- aerique 11y ago
- dx211 11y agoOK, PowerShell magic time: calc $a = Get-Process calc $a.ProcessorAffinity = 1 $a.PriorityClass = "Idle" $b = [Diagnostics.Process]::Start("PowerShell", "-c while (1) {}") $b.ProcessorAffinity = 1 Ta-da!
- iwalton3 11y agoHere is a quick clone of this project for Linux using the STOP and CONT signals: #!/bin/bash currentProcess=$(xprop -id $(xprop -root | grep -F '_NET_ACTIVE_WINDOW(WINDOW)' | awk '{print $5}') | grep -F '_NET_WM_PID(CARDINAL)' | awk '{print $3}') state=$(grep 'State:' /proc/$currentProcess/status | awk '{print $2}') if [[ "$state" == "T" ]] then kill -CONT $currentProcess else kill -STOP $currentProcess fi