3

I've made some programs with the pigpio library, all of them are working well, but when I try to run 2 at the same time I get this error (For the second one).

initInitialise: Can't lock /var/run/pigpio.pid.

I know that the first one is acting like a daemon and that’s the problem, how do I have to start de second one to avoid this problem?

  • My guess would be that pigpio needs to record it's process ID (pid) in a file so that it can shut itself down on a crash. So, it creates the file with the ID inside it and locks the file. It is expecting to run in solo mode. Daemons like this should always run in solo mode anyway, so I doubt you'll be able to achieve what you want with it. What are you trying to do? Perhaps there's a different way to do it? – recantha Apr 18 '17 at 15:02
2

Only one program linked against the C library (pigpio) can be running at any one time. This program in effect becomes the pigpio daemon.

Many programs can talk to the pigpio daemon at the same time to manipulate GPIO. This is how pigpio Python scripts work. You can achieve pretty much the same as Python scripts by writing your program in C but linking with the pigpiod_if2 library.

There is a sort of coding versus performance trade off.

  1. For the highest performance write your program in C and link with the pigpio library. At any one time only one such program may be running and such a program automatically becomes the pigpio daemon.
  2. For the second best performance write your program in C and link with the pigpiod_if2 library to interface with the running pigpio daemon.
  3. For ease of coding write in Python to interface with the running pigpio daemon. There may or may not be a slight performance hit in terms of option 2.

In your case you could either merge both programs into the one C program or recode one or both of the programs to use the pigpio daemon.

  • Thanks for your answers, actually I´m using python in some programs and wiringPi in some others, but I don´t like python and I prefer pigpio than wiringPi, I´ll try with pigpiod_if2. Thanks again. – Neto Apr 18 '17 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.