1

I am developing a PHP web interface to manage the GPIO of my Raspberry. I would like to create a page with for example four buttons:

  • Button 1: switch ON PIN1
  • Button 2: switch OFF PIN1
  • Button 3: switch ON PIN2
  • Button 4: switch OFF PIN2

To each button of the PHP page, I am associating a C program. So if i want to switch on the PIN1, I launch the PHP "exec" command of my program "switchOnPin1.c" and so on.

The problem is that in this way, after sometime, if I press many times the buttons, I have in my process list ("ps -aux" linux command) a lot of my C programs instances running.

Is there any way to have just one C program running so that for each button I can call always the same C program?

Thanks in advance

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
  • This has nothing specifically to do with the language (C, you claim) in which the external programs are written. Tags edited. – John Bollinger Sep 12 '17 at 21:03
  • 1
    It is possible to write a program that runs continuously, waiting to handle requests from clients. This is often called a "server", or sometimes a "daemon". But it's not clear that you need such a thing. The first question that occurs to me is why your external program does not exit, quickly, after setting the GPIO pin state. If it did then you wouldn't have the problem you describe. – John Bollinger Sep 12 '17 at 21:09
  • On Linux the script can use `ps` to see if the program is already running. Or the program can write its PID to a file, and the script can read the file and check whether that PID is still running. – Barmar Sep 12 '17 at 21:23

0 Answers0