1

is there some mechanism to be notified asynchronously when input from a 'file' is available?

I have a program that cyclically does its work. So far so good. But there also is a serial line and whenever a message appears there the program shall react immediately, do something special and then return to its eternal loop. A bit like a hardware interrupt, but fired by the info 'some input is available

Raffa
  • 32,237
  • Please clarify the situation you are dealing with and the result you are looking for and include examples if possible. Your question is not quiet clear enough. Thank you – Raffa Jan 08 '21 at 22:04
  • @Raffa I have a program that cyclically does its work. So far so good. But there also is a serial line and whenever a message appears there the program shall react immediately, do something special and then return to its eternal loop. A bit like a hardware interrupt, but fired by the info 'some input is available'. Best regards - M' – M. Keith Jan 09 '21 at 10:20
  • If yor program is managed by a shell script, you can add something in the script like notify-send "some input is available" right after the part where you say "the program shall react immediately, do something special " . It is however still unclear to me whether this is what you need. It would be helpful if you can [edit] and add the code that you use in your script and indicate where and how you want the notification. – Raffa Jan 09 '21 at 13:00

1 Answers1

0

If you are asking if that's possible in bash, the answer is no; see also here:

https://stackoverflow.com/questions/37049612/equivalent-of-select-system-call-in-bash

However, there is the select() system call (see "man 2 select") which you can use in scripting languages like Perl, Ruby, Python, and of course in compiled languages like C or C++, but not in bash.

What select() does is it waits until data from any of several file descriptors is available.

HuHa
  • 3,385