Sponsored Content
Top Forums Programming How to periodically execute a function in C ?? Post 302148030 by RipClaw on Thursday 29th of November 2007 01:17:49 PM
Old 11-29-2007
Tools How to periodically execute a function in C ??

Hi,

I am looking for a C library feature, to which I can say execute a function every 10 seconds.

for Eg
Code:
#include <timer_lib.h>
fun1(){
      printf("I am still cool "); 
}

int main(){
   run(10,&fun1); // Should register & execute the function fun1 every 10 seconds
 return 0x0;
}

I am not interested in using the sleep function in a while loop or something..
Is there such a feature in the standard C library ??. I have heard about such facilities available on the kernel libraries.
 

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
Pragmatic(3pm)						User Contributed Perl Documentation					    Pragmatic(3pm)

NAME
Pragmatic - Adds pragmata to Exporter SYNOPSIS
In module MyModule.pm: package MyModule; require Pragmatic; @ISA = qw (Pragmatic); %PRAGMATA = (mypragma => sub {...}); In other files which wish to use MyModule: use MyModule qw (-mypragma); # Execute pragma at import time use MyModule qw (-mypragma=1,2,3); # Pass pragma argument list DESCRIPTION
Pragmatic implements a default "import" method for processing pragmata before passing the rest of the import to Exporter. Perl automatically calls the "import" method when processing a "use" statement for a module. Modules and "use" are documented in perlfunc and perlmod. (Do not confuse Pragmatic with pragmatic modules, such as less, strict and the like. They are standalone pragmata, and are not associated with any other module.) Using Pragmatic Modules Using Pragmatic modules is very simple. To invoke any particular pragma for a given module, include it in the argument list to "use" preceded by a hyphen: use MyModule qw (-mypragma); "Pragmatic::import" will filter out these arguments, and pass the remainder of the argument list from the "use" statement to "Exporter::import" (actually, to "Exporter::export_to_level" so that Pragmatic is transparent). If you want to pass the pragma arguments, use syntax similar to that of the -M switch to perl (see perlrun): use MyModule qw (-mypragma=abc,1,2,3); If there are any warnings or fatal errors, they will appear to come from the "use" statement, not from "Pragmatic::import". Writing Pragmatic Modules Writing Pragmatic modules with Pragmatic is straight-forward. First, "require Pragmatic" (you could "use" it instead, but it exports nothing, so there is little to gain thereby). Declare a package global %PRAGMATA, the keys of which are the names of the pragmata and their corresponding values the code references to invoke. Like this: package MyPackage; require Pragmatic; use strict; use vars qw (%PRAGMATA); sub something_else { 1; } %PRAGMATA = (first => sub { print "@_: first "; }, second => sub { $SOME_GLOBAL = 1; }, third => &something_else, fourth => 'name_of_sub'); When a pragma is given in a "use" statement, the leading hyphen is removed, and the code reference corresponding to that key in %PRAGMATA, or a subroutine with the value's name, is invoked with the name of the package as the first member of the argument list (this is the same as what happens with "import"). Additionally, any arguments given by the caller are included (see "Using Pragmatic Modules", above). EXAMPLES
Using Pragmatic Modules 1. Simple use: use MyModule; # no pragmas use MyModule qw (-abc); # invoke C<abc> use MyModule qw (-p1 -p2); # invoke C<p1>, then C<p2> 2. Using an argument list: use MyModule qw (-abc=1,2,3); # invoke C<abc> with (1, 2, 3) use MyModule qw (-p1 -p2=here); # invoke C<p1>, then C<p2> # with (1, 2, 3) 3. Mixing with arguments for Exporter: (Please see Exporter for a further explanatation.) use MyModule ( ); # no pragmas, no exports use MyModule qw (fun1 -abc fun2); # import C<fun1>, invoke C<abc>, # then import C<fun2> use MyModule qw (:set1 -abc=3); # import set C<set1>, invoke C<abc> # with(3) Writing Pragmatic Modules 1. Setting a package global: %PRAGMATA = (debug => sub { $DEBUG = 1; }); 2. Selecting a method: my $fred = sub { 'fred'; }; my $barney = sub { 'barney'; }; %PRAGMATA = (fred => sub { local $^W = 0; *flintstone = $fred; }, barney => sub { local $^W = 0; *flintstone = $barney; }); 3. Changing inheritance: %PRAGMATA = (super => sub { shift; push @ISA, @_; }); 4. Inheriting pragmata: package X; @ISA = qw(Pragmatic); %PRAGMATA = (debug => 'debug'); $DEBUG = 0; sub debug { ${"$_[0]::DEBUG"} = 1; } package Y: @ISA = qw(X); %PRAGMATA = (debug => 'debug'); $DEBUG = 0; SEE ALSO
Exporter Exporter does all the heavy-lifting (and is a very interesting module to study) after Pragmatic has stripped out the pragmata from the "use". DIAGNOSTICS
The following are the diagnostics generated by Pragmatic. Items marked "(W)" are non-fatal (invoke "Carp::carp"); those marked "(F)" are fatal (invoke "Carp::croak"). No such pragma '%s' (F) The caller tried something like "use MyModule (-xxx)" where there was no pragma xxx defined for MyModule. Invalid pragma '%s' (F) The writer of the called package tried something like "%PRAGMATA = (xxx => not_a_sub)" and either assigned xxx a non-code reference, or xxx is not a method in that package. Pragma '%s' failed (W) The pramga returned a false value. The module is possibly in an inconsisten state after this. Proceed with caution. AUTHORS
B. K. Oxley (binkley) <binkley@alumni.rice.edu> COPYRIGHT
Copyright 1999-2005, B. K. Oxley. This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself. THANKS
Thanks to Kevin Caswick <KCaswick@wspackaging.com> for a great patch to run under Perl 5.8. perl v5.10.1 2009-12-09 Pragmatic(3pm)
All times are GMT -4. The time now is 09:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy