LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-09-2018, 03:02 AM   #1
ayyasprings
Member
 
Registered: Aug 2014
Posts: 96

Rep: Reputation: Disabled
Do Linux have event driven process / tasks?


Hi,

Does Linux kernel have the feature, ie the tasks which are started or driven by events and goes to sleep indefinitely (until next event occurred) ,after the executing the process by completing its purpose of invocation? Some commercial OS other than Open Source are providing this kind of feature which we have used in our organization.

Please reply!
 
Old 11-09-2018, 04:00 AM   #2
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 4,109

Rep: Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150
I’d say this principle is used in all modern operating systems, i.e. 1960s and later. GUI programs are a typical case: They consist of an event loop, where they wait for mouse clicks, the uncovering of a window and the like, process the event, and go back to sleep until the next event.

But most probably I don’t understand what you mean. Can you provide an example?
 
Old 11-09-2018, 01:50 PM   #3
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.7.1908
Posts: 4,360

Rep: Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525
Quote:
Originally Posted by ayyasprings View Post
Hi,

Does Linux kernel have the feature, ie the tasks which are started or driven by events and goes to sleep indefinitely (until next event occurred) ,after the executing the process by completing its purpose of invocation? Some commercial OS other than Open Source are providing this kind of feature which we have used in our organization.

Please reply!
Emphasis added. That pretty much describes almost everything: Mail server (smtp), web server (httpd), ftp server, ssh server, etc. They start, wait for an event, and respond. They're called daemons, or "servers"

Not sure I'd credit the kernel for them, however...

...and what berndbausch said...
 
Old 11-12-2018, 10:28 AM   #4
ayyasprings
Member
 
Registered: Aug 2014
Posts: 96

Original Poster
Rep: Reputation: Disabled
Hi,

to exactly say, for an example a process should start only based on interrupt like thing based on external event that can occur any time, and not to be inspected to start, ie like polling based check should not be there to start that process. ie)on receiving a Controller-Area-Network message the process should start as an example. After running that process it should go to sleep and should be awakened on next message receiving (like interrupt driven ), and again and again.

Do we have any feature or configuration available in Linux Kernel to perform this kind of need?

Please reply!
 
Old 11-12-2018, 10:38 AM   #5
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 4,109

Rep: Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150
I still don’t understand I am afraid. What external event? For example, a key pressed on the keyboard? There is a system call named read which blocks the process as long as there is no data for reading. The process is in the SLEEP state while it’s blocked. When data becomes available, the kernel puts the process into the RUN state, and it becomes eligible for running on a CPU. It processes the event, issues the next read and goes to SLEEP again.

Same for networking events or disk IO.

The UNIX kernel has been doing this for almost 50 years now. This is nothing special. But I think I am missing something.
 
Old 11-12-2018, 12:00 PM   #6
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.7.1908
Posts: 4,360

Rep: Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525Reputation: 1525
Quote:
Originally Posted by berndbausch View Post
I still donít understand...
Me too.
 
Old 11-14-2018, 08:10 AM   #7
ayyasprings
Member
 
Registered: Aug 2014
Posts: 96

Original Poster
Rep: Reputation: Disabled
I agree that KeyBoard inputs and Mouse inputs or Joystick inputs any kind of inputs will be processed once they are available and go to sleep after no data available. But my doubt is whether that the input data will be checked periodically for availability(ie polling based mechanism) or like hardware pin interrupt will trigger that read system call to unblock the process to handle the input data by putting it to RUN state.

How it was designed in the kernel in the above two approaches or with any other approach?

I am a newbie to Linux kernel design.
 
Old 11-14-2018, 09:04 AM   #8
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 4,109

Rep: Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150
Quote:
Originally Posted by ayyasprings View Post
I agree that KeyBoard inputs and Mouse inputs or Joystick inputs any kind of inputs will be processed once they are available and go to sleep after no data available. But my doubt is whether that the input data will be checked periodically for availability(ie polling based mechanism) or like hardware pin interrupt will trigger that read system call to unblock the process to handle the input data by putting it to RUN state.

How it was designed in the kernel in the above two approaches or with any other approach?
That depends on the driver. Some drivers might use interrupts (my guess is that most do), others might poll periodically, which also uses an interrupt, namely the timer interrupt.
Quote:
I am a newbie to Linux kernel design.
I doubt that these things are much different in Linux than UNIX or any other OS.
 
Old 11-17-2018, 02:48 AM   #9
ayyasprings
Member
 
Registered: Aug 2014
Posts: 96

Original Poster
Rep: Reputation: Disabled
Still have one more doubt.You said that the read system call will block the process until data is available.

The driver will be notified either by input interrupt or timer interrupt as you said.I am now clear with that.

My doubt is while the process is being blocked, will there be any periodic checks on behalf of that process, by any kernel code/component, to unblock the process to get CPU clocks?

Or it will also have some callback/event based mechanism so that wastage of cpu usage for periodically checking to unblock the process when data got available?

In Linux kernel how was it designed?

Please reply.
 
Old 11-17-2018, 06:05 AM   #10
berndbausch
Senior Member
 
Registered: Nov 2013
Location: Tokyo
Distribution: A few
Posts: 4,109

Rep: Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150Reputation: 1150
Quote:
Originally Posted by ayyasprings View Post

My doubt is while the process is being blocked, will there be any periodic checks on behalf of that process, by any kernel code/component, to unblock the process to get CPU clocks?
When a process waits for I/O, it is in the SLEEP state and canít use the CPU. When I/O completes, either successfully or due to an interruption or an error, the process gets back to the RUN state and is eligible to run on the CPU. It might get CPU time immediately or, if there are other RUN processes, might have to stay in a queue for a short while.
Quote:
Or it will also have some callback/event based mechanism so that wastage of cpu usage for periodically checking to unblock the process when data got available?
Periodically checking what? Why do you think CPU is wasted?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Event Driven in embedded modem prabhu69 Linux - Newbie 1 10-18-2007 10:58 AM
Event Driven Sockets kar_the_terrible Programming 3 09-23-2006 05:41 PM
Event driven connection allomeen Programming 6 02-28-2006 05:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration