c code for perpetually changing center colour in xeyes(terminal)
i'm trying to write a c code which opens the xeyes application and then those eyes keep chang开发者_如何学JAVAing its color constantly for a particular eriod of time..
i tried to achieve this by executing xeyes with one center color, adding a delay of 3 seconds, killing the process, and opening xeyes with another center colour and so on inside a loop.
on execution of this code however, the first xeyes process does not get killed and the following processes do not execute.
is there a better way of doing this?
the reason for this is that you are using the system() command, which waits until xeyes closes. This never happens, so your code never executes past your first system command.
You can find out more information about the functions you are using by typing
man system
on the command line.
I wouldn't use C to do this. You're better off using a shell script that launches xeyes in the background, sleeps, then kills it and launches it again. It's probably on the order of 5 lines.
That said, in order to get a timer to run while xeyes is running instead of after it closes, you need to fork off your xeyes process and run the timer that waits to kill it in a separate process. You might want to look into the functions from spawn.h.
精彩评论