1 Reply Latest reply on Sep 14, 2016 4:02 AM by gavinkoh70

    System calls and process termination

    gavinkoh70

      I am starting a perl script that runs forever listening to a port. It is invoked as such:

      system("perl home/root/portlistener.pl 100 &");

       

      But now, I have a new requirement to implement a button that is supposed to "close" the port and free up resources. So, when the user taps the button on the resistive touch display, I should kill the perl process. But, how do I kill the perl process when I don't have the PID?

       

      I know you can do something like the script below to echo the PID:

      perl home/root/portlistener.pl 100 & echo$!

       

      Or I could run something like:

      ps | grep portlistener

       

      But how do I retrieve the PID real-time from within my Arduino code?

       

      Once I retrieve the PID, I can issue a

      system("kill xxx");

      to kill the process.

       

      Or is there a much better way?

       

      Thanks.