Thursday, February 25, 2010

Suspend and resume any program using SIGSTOP UNIX

If you've ever been running a program that requires a lot of CPU or hits the disk heavily, and then wanted to be able to use your computer for something else for a few minutes, this is the hint for you.

Most UNIX people know they can use Control-Z and the bg and fg commands to control whether or not their programs are running. What many often don't know is that you can do the same thing using signals. For instance, let's say I am doing a long build in Project Builder, but I need to use my computer for a few minutes at full speed to do something else. Here's how to accomplish that:
  1. Find the process ID of the program you want to suspend using either the ps wwwaux command from the shell or via Process Viewer (in /Applications -> Utilities):
    /Users/sam:> ps auxwww | grep Project
    sam        814   0.0  0.6   114984   5900  ??  S     4:24PM
      0:01.56  /Developer/Applications/Project Builder.app/
      Contents/MacOS/Project Builder -psn_0_5636097
    Here the id is 814 (line breaks were added above for narrower display width).

  2. Use the kill command and send it a SIGSTOP signal:
    /Users/sam:> kill -SIGSTOP 814
    The program will now stop doing whatever it was doing and you can then do a quick render or whatever it was that needed the whole machine.
To resume your program right back where it was, just use the kill command and send it a SIGCONT signal:
/Users/sam:> kill -SIGCONT 814
It's as easy as that. I'm sure some enterprising individual could make a graphical program that does this for you, but I'm a UNIX user at heart.




Links:
http://www.macosxhints.com/article.php?story=20030915193440334


No comments:

Post a Comment

 Linux Interview  Linux booting process EXT4 XFS file system runlevel scan disk hba driver systool -c fc_host lspci -nn | grep -i hba single...