electroRF Member Feb 6, 2014 #1 Hi, In the BBB (beagleboneblack), the following program changes the LED's state: Code: int main() { FILE *led; led = fopen("/sys/class/leds/beaglebone:green:usr3/brightness", "w"); while(1) { fprintf(led,"%d",1); fflush(led); pauseSec(1); fprintf(led,"%d",0); fflush(led); pauseSec(1); } fclose(led); return 0; } How does it work? Is there an interrupt when the file "brightness" is written, which changes the LED's state according to the input? Or other method for checking the file's content? Thank you.
Hi, In the BBB (beagleboneblack), the following program changes the LED's state: Code: int main() { FILE *led; led = fopen("/sys/class/leds/beaglebone:green:usr3/brightness", "w"); while(1) { fprintf(led,"%d",1); fflush(led); pauseSec(1); fprintf(led,"%d",0); fflush(led); pauseSec(1); } fclose(led); return 0; } How does it work? Is there an interrupt when the file "brightness" is written, which changes the LED's state according to the input? Or other method for checking the file's content? Thank you.
NorthGuy Well-Known Member Feb 6, 2014 #2 "/sys" is a special filesystem designed for ordinary programs to communicate with Kernel. There's no real files behind it. When you read/write to it, it goes directly from/to the Kernel.
"/sys" is a special filesystem designed for ordinary programs to communicate with Kernel. There's no real files behind it. When you read/write to it, it goes directly from/to the Kernel.
P Pommie Well-Known Member Most Helpful Member Feb 6, 2014 #3 FYI, the code after the while(1) loop will never get executed and is therefore not needed. Mike.
electroRF Member Feb 6, 2014 #4 Thank you NorthGuy and Mike! NorthGuy Thanks, it makes sense. It is correct for all the files in /sys folder and its sub folders? I thought there would be system-calls to interface Linux Kernel, are there? Pommie Oh you're right. How then this process ever gets terminated? When it does terminate, would it close the "file"? * BTW, what is the fflush(led); for? Last edited: Feb 6, 2014
Thank you NorthGuy and Mike! NorthGuy Thanks, it makes sense. It is correct for all the files in /sys folder and its sub folders? I thought there would be system-calls to interface Linux Kernel, are there? Pommie Oh you're right. How then this process ever gets terminated? When it does terminate, would it close the "file"? * BTW, what is the fflush(led); for?
NorthGuy Well-Known Member Feb 7, 2014 #5 electroRF said: Thanks, it makes sense. It is correct for all the files in /sys folder and its sub folders? Click to expand... Yes, /proc is a different filesystem of the same kind electroRF said: I thought there would be system-calls to interface Linux Kernel, are there? Click to expand... Yes, but they're not used for drivers.
electroRF said: Thanks, it makes sense. It is correct for all the files in /sys folder and its sub folders? Click to expand... Yes, /proc is a different filesystem of the same kind electroRF said: I thought there would be system-calls to interface Linux Kernel, are there? Click to expand... Yes, but they're not used for drivers.
electroRF Member Feb 7, 2014 #6 Thank you NorthGuy! I'm going to get a project in job which involves working with VxWorks. As I've never worked with OS before, I'm practicing Linux. Do you have an advice how I could practice multi-process programming?
Thank you NorthGuy! I'm going to get a project in job which involves working with VxWorks. As I've never worked with OS before, I'm practicing Linux. Do you have an advice how I could practice multi-process programming?
NorthGuy Well-Known Member Feb 7, 2014 #7 electroRF said: Do you have an advice how I could practice multi-process programming? Click to expand... Do you mean multiprocess (as involving inter-process communications) or multithread (as several threads running at the same time) ?
electroRF said: Do you have an advice how I could practice multi-process programming? Click to expand... Do you mean multiprocess (as involving inter-process communications) or multithread (as several threads running at the same time) ?
electroRF Member Feb 7, 2014 #8 Hi NorthGuy! I actually meant for both, I wanna practice both multi-threaded process and multi-process programming.
Hi NorthGuy! I actually meant for both, I wanna practice both multi-threaded process and multi-process programming.