Page 1 of 1

Import using 100% CPU

Posted: 2008-05-20T08:53:01-07:00
by Justin Hendrickson
I want to use import to take regular pictures of my desktop, so I setup a bash script to sleep 10 minutes, then use import and repeat.

Code: Select all

#!/bin/bash
while true; do
    directory=/home/jhendric/screenshots/`date +%b%d`

    if [ ! -e "$directory" ]; then
        mkdir $directory
    fi

    import -window root -silent $directory/`date +%H%M`.gif

    sleep 10m
done
The only issue is that import uses 100% CPU every time it runs, so X locks up for 3-5 seconds while import runs. I tried using nice, but it didn't help any.

I know it's a bit of an off-topic question, but I thought I'd ask since it'd be helpful for me.

Re: Import using 100% CPU

Posted: 2008-05-20T10:33:33-07:00
by magick
Add -screen to your command line, that may help. Otherwise, the delay is expected. The X server is locked so the pixels do not change while a snapshot is taken.

Re: Import using 100% CPU

Posted: 2008-05-22T07:47:09-07:00
by Justin Hendrickson
I found an alternative to import, called xwd (http://en.wikipedia.org/wiki/Xwd), that doesn't cause a 100% CPU spike while running. Here's the script, for anyone that cares.

Code: Select all

#!/bin/bash
while true; do
    directory=/home/jhendric/screenshots/`date +%b%d`

    if [ ! -e "$directory" ]; then
        mkdir $directory
    fi

    xwd -root | convert - $directory/`date +%H%M`.png

    sleep 10m
done

Re: Import using 100% CPU

Posted: 2008-06-04T22:43:59-07:00
by anthony
There is also a lower level standard X window utility called "xwd" to take snapshots. however its out put is the 'xwd' format but IM understands this so that is no drama.

Code: Select all

xwd -root | convert - snapshot.png
By default it 'beeps' once at the start and twice at the end, which can get annoying, so adding -silent to the options is a good idea too.

PS; the default xwd converter is xwud

Code: Select all

xwd -root | xwud