C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 07-19-2004, 04:16 AM   #1
Registered User
 
gandalf_bar's Avatar
 
Join Date: Oct 2003
Posts: 92
Daemon problem

I am making program that can change wallpapers in Gnome desktop when you switch workspace and for periodic time. Assume that you have 3 workspace and for each workspace ( or virtual desktop ) you have each list. So for workspace number one, you have 4 hot chicks themed wallpapers ( Britney.png, Madonna,jpg, etc ). Workspace number two, you have 3 Super Hero themed wallpapers ( Superman.jpg, Spiderman2.png, etc ). Workspace 3, you have 2 Cartoon wallpapers.

Assume for 00:00 time, you are in workspace ( ws ) 2, you got Spiderman2.png wallpaper. If you change to ws 1, you will get Britney.png wallpaper, if you change to ws3, you will get Donald.png. But you don't change the ws. you just wait one minute. 01:00. Now you wallpaper change in your current ws( that is number 2 ) to Superman.jpg. If you change to ws 1, you will get Madonna.png wallpaper not Britney anymore, if you change to ws3, you will get MickeyMouse.png not Donald anymore.

What is the best way to randomize this list? Threads? So for this case, I am making three threads. Thread 1 randomize 4 wallpapers. Thread 2 randomize 3 wallpapers. Thread 3 randomize 2 wallpapers. Or just forking the child process?

That is question number one.

This is the rough daemon source code:

Code:
string wallpaper;
int workspace, dump;
const int forever = 1;
while( forever )
{
       //check if the workspace change
       workspace = whatWorkspaceIsIt();
       //if still the same
       if( previous_workspace == workspace )
       {
               //check if has passed 60 seconds
               dump = getCurrentTime() - previousTime;                    
               if( dump >= 60 )
               {
                       //here we ask the information from thread or child process that randomize 
                       wallpaper = getCurrentWallpaper( workspace );  
                       changeTheWallpaper( wallpaper );
                       previousTime = getCurrentTime(); 
                }
       }
        else
        {
                previousTime = getCurrentTime();
                wallpaper = getCurrentWallpaper( workspace );
                changeTheWallpaper( wallpaper );
         }

         previous_workspace = workspace;
}
This daemon take up too much CPU usage. How do I press it down beside use nice function? How do I improve my algorithm for this daemon? To make it short, my daemon checking all the time what workspace is it. I don't surprise if the daemon has checked what workspace it is for more than ten times under one seconds. The problem is that to get clue what workspace it is, I have to forking another process to find out. Then I read the stdout from the program. By that way, only I can know what workspace it is.

Ideally it would be better if I can hacked the workspace swithcer source code. So the wallpaper changer is included in workspace switcher. So if you change the workspace , it will automatically change the wallpaper. But it is in C. And I am still newbie...... And it is not easy to read somebody sourcecode.
__________________
A man asked, "Who are you?"
Buddha answered, "I am awaked."
gandalf_bar is offline   Reply With Quote
Old 07-19-2004, 09:29 AM   #2
Obsessed with C
 
chrismiceli's Avatar
 
Join Date: Jan 2003
Posts: 501
It took up too much cpu because it is always comparing dump to 60. What you should do, when you know sixty seconds has elapsed, tell your daemon to sleep for 60 seconds. This way your program won't get scheduled and won't check dump to 60 until at least 60 seconds has passed. Do you see what I am saying?
__________________
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
chrismiceli is offline   Reply With Quote
Old 07-19-2004, 10:14 PM   #3
Registered User
 
gandalf_bar's Avatar
 
Join Date: Oct 2003
Posts: 92
The problem is.... when I use your approach.... :
00:00, I am in ws 2.... my wallpaper is Superman.jpg now.
If I wait for 60 seconds ( my daemon sleep for 60 seconds ) and I don't change ws, that would be no problem. Then my daemon wake up after 60 seconds. 01:00. Ok, time to change wallpaper now. Now my wallpaper is SpiderMan2.png. Happily ever after.
Now here's come the problem:
If after 15 seconds, that is 00:15, I change to ws 1, the daemon didn't change wallpaper because it is still sleeping ( it is still under 60 seconds ). But it <b> should </b> change the wallpaper to Britney.jpg or Madonna.png. Or if I change to ws 3 after 15 seconds ( under 60 seconds ), it <b> should </b> change the wallpaper to Donald.jpg or MickeyMouse.png. But it didn't because the daemon is still sleeping.
That is the problem.
ws = workspace or virtual desktop
wallpaper in workspace 1 = Britney.jpg, Madonna.png ( hot chick wallpapers )
wallpaper in workspace 2 = Superman.jpg, SpiderMan2.png ( superhero wallpapers )
wallpaper in workspace 3 = Donald.jpg, MickeyMouse.png ( cartoon wallpapers )
__________________
A man asked, "Who are you?"
Buddha answered, "I am awaked."
gandalf_bar is offline   Reply With Quote
Old 07-20-2004, 06:23 AM   #4
Obsessed with C
 
chrismiceli's Avatar
 
Join Date: Jan 2003
Posts: 501
Then you need to wake your program with a signal when you change from a ws then. I don't know how you would go about doing that, though.
__________________
Help populate a c/c++ help irc channel
server: irc://irc.efnet.net
channel: #c
chrismiceli is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
daemon problem please help fairyjerry14 C Programming 2 09-07-2007 02:43 AM
Someone having same problem with Code Block? ofayto C++ Programming 1 07-12-2007 08:38 AM
A question related to strcmp meili100 C++ Programming 6 07-07-2007 02:51 PM
WS_POPUP, continuation of old problem blurrymadness Windows Programming 1 04-20-2007 06:54 PM
Laptop Problem Boomba Tech Board 1 03-07-2006 06:24 PM


All times are GMT -6. The time now is 09:57 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22