Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9873 Discussions

System calls and process termination

idata
Community Manager
1,419 Views

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.

0 Kudos
1 Solution
idata
Community Manager
137 Views

Solved via a call to another PERL script that uses the same port number (shown as 100 in the example above).

perl home/root/stoplistener.pl 100

Inspiration for stoplistener.pl can be found http://forums.devshed.com/perl-programming-6/process-list-script-perl-linux-872135.html here and http://http//stackoverflow.com/questions/3129238/how-do-i-stop-a-process-running-using-perl here.

Ultimately relied on this command to list out the PIDs:

ps | grep "portlistener 100"

Regards,

Gavin

View solution in original post

1 Reply
idata
Community Manager
138 Views

Solved via a call to another PERL script that uses the same port number (shown as 100 in the example above).

perl home/root/stoplistener.pl 100

Inspiration for stoplistener.pl can be found http://forums.devshed.com/perl-programming-6/process-list-script-perl-linux-872135.html here and http://http//stackoverflow.com/questions/3129238/how-do-i-stop-a-process-running-using-perl here.

Ultimately relied on this command to list out the PIDs:

ps | grep "portlistener 100"

Regards,

Gavin

Reply