Doubt with signals and sleep function


 
Thread Tools Search this Thread
Top Forums Programming Doubt with signals and sleep function
# 1  
Old 08-27-2013
Doubt with signals and sleep function

Hi , I have a doubt with signals and sleep function.

In a program i have this

Code:
while(1)
{
   //do some work
   sleep(1);
}

And in a thread i have something like this
Code:
    union sigval data;
    char message[1024];
    char msg[1024];
    data.sival_int=0;

    while(1)
    {
        message[0]='\0';
        //Do some work and wait for some events
        strcpy(msg,message);
        datos.sival_ptr=msg;
        sigqueue(getpid(),SIGUSR1,data);
    }

But for some reason , when i send the signal sometimes sleep(1) not execute!
Anybody knows why this happen? Or this shouldn' t happen?

Thanks and bye!
# 2  
Old 08-27-2013
Check the return value on sleep() to see what it thinks its doing.
# 3  
Old 08-27-2013
Also post your signal setup and signal handling code.
# 4  
Old 08-27-2013
Corona688 thank you ! i only need read the man of sleep...

Sleep when is interrupted , stop it and return the number of seconds that are missing.... so i put a while until sleep finish and ....it works! (or i believe that works).
# 5  
Old 08-27-2013
That may work, yes. And errno may tell you more about why it's returning early.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oracle function invoked from shell script doubt

hi gurus, I have tried myself to invoke an oracle function. there are three different function available need to be called for differnt. can you tell me whether the below code is correct to call oracle function from shell script. Any help would be highly appreciated. cat location.sh ... (5 Replies)
Discussion started by: arun888
5 Replies

2. Programming

Sleep function not detected

Hello Im using geany to write my c codes. Below is my code to make the internal LED of beaglebone flashing. But i cant seem to use the sleep or delay to make the program wait for a couple of miliseconds. I've included all include files that i can find but none of it solve the problem. Any help is... (1 Reply)
Discussion started by: HellRyder
1 Replies

3. Shell Programming and Scripting

How the Sleep function will work?

Hi All, I am new to Unix , there i am facing one problem with sleep command. that is .. in while loop i have defined sleep function .. my condition is like this while #i knew this is infinite loop do sleep 200 echo "hello " done. this condition will never become .. true... (3 Replies)
Discussion started by: mandlysreedhar
3 Replies

4. Programming

Trivial doubt about C function pointer

Hi, In the below C code, #include <stdio.h> void print() { printf("Hello\n"); } int main() { void (*f)() = (void (*)()) print; f(); (*f)(); } I wonder, how the syntaxes "f()" and "(*f)()" are treated as same without any error? Is this an improvement or ANSI/ISO... (1 Reply)
Discussion started by: royalibrahim
1 Replies

5. Programming

C Sleep function hangs @ __kernel_vsyscall ()

This is the gdb backtrace. ^C Program received signal SIGINT, Interrupt. 0xffffe424 in __kernel_vsyscall () (gdb) bt #0 0xffffe424 in __kernel_vsyscall () #1 0xb7e56a70 in __nanosleep_nocancel () from /lib/libc.so.6 #2 0xb7e568bb in __sleep (seconds=0) at sleep.c:138 #3 0x080496d5 in... (6 Replies)
Discussion started by: dragonpoint
6 Replies

6. Shell Programming and Scripting

Help with sleep function

Hey everyone, just entering the linux world, I need some help with a shell script i'm trying to write, the purpose is to check every 10 minutes what was the last time a certain file was modified, and if there is a connection to the server at this moment send an email with the date of the... (2 Replies)
Discussion started by: moshe88
2 Replies

7. Shell Programming and Scripting

Wrapping 'sleep' with my 'resleep' function (Resettable sleep)

This is a very crude attempt in Bash at something that I needed but didn't seem to find in the 'sleep' command. However, I would like to be able to do it without the need for the temp file. Please go easy on me if this is already possible in some other way: How many times have you used the... (5 Replies)
Discussion started by: deckard
5 Replies

8. Shell Programming and Scripting

Function call with argument doubt

Hi all, I am having a problem with user defined function call. I am new into the concept of shell script UDFs. My function is: iterate_directory() { cd $1 k=0 for i in * do if then ARR=${i} fi done echo ${ARR } } (4 Replies)
Discussion started by: canishk
4 Replies

9. UNIX for Dummies Questions & Answers

Signals...

(posted this in the scripting forum as well, but figured it should go here) So, what's going on is this: For our program, we had to create our own shell, and if the user pressed ctrl-c just at the cmdline, then this signal would be ignored, but if there is a foreground process running, let's... (0 Replies)
Discussion started by: blind melon
0 Replies
Login or Register to Ask a Question