This bash command lists all running processes, find all lines with "programname" and count the lines.. if this return 1 or more, your program is running.
So one way of solving this is to run this command with system() or popen() and get the result.

Another way is to learn how the /proc filesystem works and go trough that.

This bash command lists all running processes, find all lines with "programname" and count the lines.. if this return 1 or more, your program is running.
So one way of solving this is to run this command with system() or popen() and get the result.

Another way is to learn how the /proc filesystem works and go trough that.

Rather than using bash file I would like to use more like c language because according to connection status my already running program should blink a link or not.

The third column of the output will tell you whether or not the program is running (i.e., that which is the goal of this exercise). If this field contains the letter R (in upper case), then you know that it is running. Most programs, most of the time, will be sleeping and this field will contain an S. It may also be stopped, in which case, it will contain a T.

Rather than using bash file I would like to use more like c language because according to connection status my already running program should blink a link or not.

I dont understand your argumentation. I'm just saying that you can run a bash command from C/C++ to get the information you need. And you can do it in like 5 lines of code.

or... you can look at the code behind a "ps" command : https://gitlab.com/procps-ng/procps
or.. you can make a routine that goes trough all the directories in "/proc" which is a number ( PID) and look and the "cmdline" file in each of them and see if that matches your program..

... but I'm rather confident that in the end you will be back looking at my original suggestion.

This bash command lists all running processes, find all lines with "programname" and count the lines.. if this return 1 or more, your program is running.
So one way of solving this is to run this command with system() or popen() and get the result.

Another way is to learn how the /proc filesystem works and go trough that.

just out of curiousity:
which would be the system() command not only to execute a shell command but also to retieve a value from it?

just out of curiousity:
which would be the system() command not only to execute a shell command but also to retieve a value from it?

popen() to start the program and open a pipe to it.
Can then read the data from the pipe, using the same methods you can use to read data from a file.
There are no convenient execute-command-and-return-data-as-string methods by default.

In the case of the TS it may be easier to just use the pidof command, and look at the numeric exit code though:

dsyleixa123 wrote:
just out of curiousity:
which would be the system() command not only to execute a shell command but also to retieve a value from it?

Just redirect stdout when running the command, make sure that what you redirect to is something you can read. Many use a file, though I would only recomend that if you have a custom RAM FS setup on your linux for the purpose.

This is basic C programming, you can look in your copy of "The C Programing Language" for more details on redirecting stdout.

RPi = The best ARM based RISC OS computer around
More than 95% of posts made from RISC OS on RPi 1B/1B+ computers. Most of the rest from RISC OS on RPi 2B/3B/3B+ computers