Re: sleep function and timer in C

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hello Vincenzo...

> can anyone tell me if there's a relation between the sleep() C
> function and the implementation of timers in Linux?
> I know there's a relation between alarm() system call and timers, as
> alarm() calls the kernel function settimer() that initializes
> real_timer field of the calling process.

Let's hope I understand you correctly. IMHO, yes, there is a correlation 
between sleep() and timer's implementation in kernel

In general, kernel does below steps when a process wants to put itself 
in sleep (TASK_INTERRUPTIBLE) state:
1. Create dynamic timer (via init_timer). The interval is defined here
2. Inside the new declared timer, define a function to wake up the 
current process (process which wants to sleep)
3. Activate the timer and do schedule()
4. If the timer expired, timer's function calls wake_up_process with the 
saved process descriptor (the one who sets the timer). This means 
changing the process' stated back into TASK_RUNNING and reinsert it to 
back to run queue. need_resched field of current process is set to 1 to 
denote a need of rescheduling

Does it answer your question?

regards

Mulyadi


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux