Sponsored Content
Top Forums Programming How to periodically execute a function in C ?? Post 302152470 by WebKruncher on Thursday 20th of December 2007 12:41:28 AM
Old 12-20-2007
Great feedback!

This might be about the coolest site I've ever seen. Anyway, diplomacy is over-rated Smilie

I don't disagree at all about the performance hit. I came up with the C++ object just to pack all of whatever it's gonna do into something that can be tucked away in a generic library and offer an easy way to trigger something. I like it because it keeps all the dirty work of checking the clock out of the main code. So, the utility can look something like:

// xxx is each of sound, graphics_cache, file_activity, port_status, whatever_else
struct xxx_Manager : Chronisitcs
{
xxx_Manager(int ms) : Chronistics(ms) {}
virtual bool operator()();
}

bool xxx_Manager:Smilieperator()()
{
if (!trigger()) return false;
// it's time to do whatever an xxx manager should do
return true;
}

while (1)
{
// just do whatever you normally do...
// each line turns out to be a function object based on the Chonistics thingy
sound_manager();
graphic_cache_manager();
geometry_manager();
collision_manager();
file_activity_manager();
port_status_manager();
magic_spell_manager();
socket_service_manager();
whatever_else_manager();
// probably need some kind of system call here or you'll tank.
// usually a short sleep does the trick.
usleep(10);
}

...and all the logic of determining when to actually do the stuff is handled in the Chronistic guts. However it's done, it happens exactly the same way for every Chronistic derivative. And, of course then, you can have stacks and deques and maps of managed objects, and traverse them, sort them, update them in whatever order you want, index them, well, you get the point. It can get pretty interesting.

But, what I really want to know is, what is the best way to get the kernel to signal something periodically. And, can it be done without a worker thread?

Last edited by WebKruncher; 12-20-2007 at 02:12 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I execute own ksh function in find -exec

Hi, I wrote a smiple ksh function send_notification() { ... } and want to execute it on each file, matched by the find command. I tried: find / -name "*.err" -mtime -8 -exec send_notification {} \; but it doesn't work. What should I do? I work in ksh on Hp-Ux. Regards, Pit (11 Replies)
Discussion started by: piooooter
11 Replies

2. Shell Programming and Scripting

How to execute local function in awk

Hi All, Can you please tell me how to execute local function written in a shell script with awk. i tried with system command but its giving an error. (1 Reply)
Discussion started by: krishna_gnv
1 Replies

3. UNIX for Advanced & Expert Users

Unable to execute a function using trap

I have a script A which calls script B. I wrote a function in script A to be executed when Kill command is issued for script A and I invoke that function using the trap command.The function identifies all child process running under script A (in this case script B) and kills the child process and... (3 Replies)
Discussion started by: smohandass
3 Replies

4. Shell Programming and Scripting

understand the function to execute

Gurus, Can you please tell me why this script is executing but i am getting no result...also can you tell me what is this gettime() doing? in a script i wrote this hour.SH -------------------------- gettime() { date '+%H' | { read hour TIME=${hour} } } : ----------------------... (2 Replies)
Discussion started by: RubinPat
2 Replies

5. UNIX for Dummies Questions & Answers

[ASK]execute shell with function in solaris

dear all i need your advice in shell with solaris i have testing script like this #!/usr/bin/bash function test(){ echo "testing only" } ## execute function ## test but if i running always got error like this test.sh: syntax error at line 1: `(' unexpected who can i running this... (7 Replies)
Discussion started by: zvtral
7 Replies

6. Shell Programming and Scripting

Execute a function in background and then suspend it

Here is some back ground on the script. The script is to poll an arbitrary number of DB's. To do this I am creating a function that takes the file_path to the DB and the min poll interval as arguments. The function will be called for each DB and then ran in the background. The function I was... (6 Replies)
Discussion started by: ryandavison
6 Replies

7. Shell Programming and Scripting

MQ depth Periodically

Hi I am trying to a write a script which gives message queue depth for every 5 mins in a file. Commands that I use are runmqsc QM_Name display ql(*) curdepth Since I can use only MQSC commands I need help on how to fetch the output on to a file after executing display command. (3 Replies)
Discussion started by: jhilmil
3 Replies

8. Shell Programming and Scripting

Want to use function and execute the below query in script.

#!/bin/bash function getDeliveredDispatches(firstDateTime, lastDateTime, limit) { var cursor = db.dispatches.find( {$and: }} ]}, {"deliveryGroupId" : 1, "batchId": 1, "statusHistory.code" : 1} ); var wrongDispatchesIds = ; print("Number of dispatches selected based on filter = " +... (2 Replies)
Discussion started by: neel2462
2 Replies

9. Shell Programming and Scripting

Need help to write a function in shell scripting to execute sql files

Hi, I am new to shell scripting and i need to write a automation script to execute sql files. I need to check the table if it is there in system tables and need to write a function to call the .sql files. For ex. I have a.sql,b.sql,c.sql files, where the sql file contains DELETE and INSERT... (1 Reply)
Discussion started by: Samah
1 Replies

10. Shell Programming and Scripting

Execute function as soon as input is provided in menu drive shell script

Hi All, I have a menu driven scripts. As you know while running the script we have to input the option such as 1,2, and 3 to execute function accordingly. but after selecting the input we have to press Enter. My requirement is to execute function as soon as we press the option. Is there... (5 Replies)
Discussion started by: kiran_j
5 Replies
std::tr2::bool_set(3)					     Library Functions Manual					     std::tr2::bool_set(3)

NAME
std::tr2::bool_set - SYNOPSIS
Public Member Functions constexpr bool_set () constexpr bool_set (bool __t) bool contains (bool_set __b) const bool equals (bool_set __b) const bool is_emptyset () const bool is_indeterminate () const bool is_singleton () const operator bool () const Static Public Member Functions static bool_set emptyset () static bool_set indeterminate () Friends bool_set operator! (bool_set __b) bool_set operator& (bool_set __s, bool_set __t) template<typename CharT , typename Traits > std::basic_ostream< CharT, Traits > & operator<< (std::basic_ostream< CharT, Traits > &__out, bool_set __b)" bool_set operator== (bool_set __s, bool_set __t) template<typename CharT , typename Traits > std::basic_istream< CharT, Traits > & operator>> (std::basic_istream< CharT, Traits > &__in, bool_set &__b)" bool_set operator^ (bool_set __s, bool_set __t) bool_set operator| (bool_set __s, bool_set __t) Detailed Description bool_set See N2136, Bool_set: multi-valued logic by Herve Bronnimann, Guillaume Melquiond, Sylvain Pion. The implicit conversion to bool is slippery! I may use the new explicit conversion. This has been specialized in the language so that in contexts requiring a bool the conversion happens implicitly. Thus most objections should be eliminated. Definition at line 54 of file bool_set. Constructor &; Destructor Documentation constexpr std::tr2::bool_set::bool_set () [inline] Default constructor. Definition at line 59 of file bool_set. constexpr std::tr2::bool_set::bool_set (bool__t) [inline] Constructor from bool. Definition at line 62 of file bool_set. Member Function Documentation bool std::tr2::bool_set::equals (bool_set__b) const [inline] Return true if states are equal. Definition at line 69 of file bool_set. bool std::tr2::bool_set::is_emptyset () const [inline] Return true if this is empty. Definition at line 73 of file bool_set. bool std::tr2::bool_set::is_indeterminate () const [inline] Return true if this is indeterminate. Definition at line 77 of file bool_set. bool std::tr2::bool_set::is_singleton () const [inline] Return true if this is false or true (normal boolean). Definition at line 81 of file bool_set. Referenced by operator bool(). std::tr2::bool_set::operator bool () const [inline] Conversion to bool. Definition at line 86 of file bool_set. References is_singleton(). Author Generated automatically by Doxygen for libstdc++ from the source code. libstdc++ Tue Jun 10 2014 std::tr2::bool_set(3)
All times are GMT -4. The time now is 08:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy