Raspberry Pi Asked by Balaji G on November 15, 2021
I have a program that talks to a ttyACM0 usb device. When the USB bus is power-cycled the program is supposed to re-initialize the device handle.
The program executes properly and re-initializes the Device-handle on USB power-cycle when called from the command-line
Program executes properly if rc.local script is called after its called at-least once from the command line during a given session.
If I boot the system rc.local executes but once the USB power-cycle starts the process is getting killed by the OS (atexit() printfs are not logged)
I have tried compiling the code over a fresh raspbian strech install and the problem still persists.
Can somebody throw some light behind this issue?
I have been stuck on this issue for a week now.
Any help is appreciated.
This is the rc.local file
#!/bin/sh -e
#
# rc.local
exec >>/data/rc_log.txt 2>&1
/root/bin/proc &
sleep 2
exit 0
The program gets sensor data from the ttyACM device and put it in a variable in a shared memory for another process to access and I need to it do so continuously, hence if the usb is removed, the program goes to sleep and once the usb is reconnected the program gets access again to the device and resumes
The program works properly when called from the command line using ./proc and it pauses and resumes when usb is removed or reattached. But when I reboot the rpi and make the program run from rc.local it works only till the device is connected and it exits once its disconnected from usb
The program is started and I can see it on htop, also my other process is getting sensor data from it. Once the usb device is removed the program dissappears from htop and since my ExitHandler is not being called as I cannot see any output in log I am assuming that the program is getting killed by the kernel.
A service started by init (which in the case of Raspbian and most other current GNU/Linux is systemd) is presumed to be a background process, unless special arrangements are made. A process which does not appropriately fork to the background within a small amount of time (seconds) will generally be killed by init.
What you describe is appropriate to a background process, but it sounds as if it is being run in the foreground like this:
/path/to/whatever/myprocess
Instead, if using /etc/rc.local
you should fork it using POSIX shell syntax (&
):
/path/to/whatever/myprocess &
exit 0
The exit 0
is there in the original script; it should remain the last line and you should ensure the script completes within a few seconds.
There may be complications if the process writes to standard output or error, in which case you should redirect that:
/path/to/whatever/myprocess > /dev/null 2>&1 &
This will throw the output away but you can use a logfile instead of /dev/null
, see also:
Answered by goldilocks on November 15, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP