[maemo-developers] Check if application is run

From: Aleksandr Koltsoff czr at iki.fi
Date: Thu Nov 15 11:21:11 EET 2007

Eero Tamminen wrote:
> ext Aleksandr Koltsoff wrote:
>> Eero Tamminen wrote:
>>> ext Aleksandr Koltsoff wrote:
>>>> I think in your case it would be sufficient to do something like this:
>>>> .. snip ..
>>>> while(1) {
>>>>   system("./run-your-application params");
>>>>   sleep(2);
>>>> }
> .. big snip .. 
>> If the application is completely broken, and will fail to start in any
>> case, then this would amount to polling, and would shorten battery life.
> This would happen also if the process daemonizes itself.

Indeed. In that case the above starting loop would eventually cause N
copies of the child to run (barring exclusive resource usage inside the
child) and would eventually result in dragons flying out of ones nose. I
guess the original context was "how to run and restart an SDL game". I
didn't assume that the game would daemonize itself :-).

Should the program (I'll ignore the SDL-game now) daemonize itself, one
is left with the original second problem though. Since the daemonized
process is no longer a child process to the starter, how does the
starter know when the now daemonized child will terminate? (since
daemonization involves moving under init directly and breaking the
original parent<->child relationship). This brings us back to the issue
that Linux doesn't have a non-polling solution to wait until some PID
exits (and even the polling ones are racy, but triggering that race
would require quick PID-space exhaustion between the polls).

This problem isn't by any means to related to ITs though.

> ext Aleksandr Koltsoff wrote:
>> My original post did suggest handling exit codes of the child properly,
>> but I guess that was lost somewhere in the process..
>>>> Linux (kernel) does not have a non-polling mechanism to track
>>>> PID-existance for non-related processes.
>> Eero Tamminen wrote:
>>> It has, you just need to be the process parent.  :-)
> ext Aleksandr Koltsoff wrote:
>> Note the "non-related" part :-). Parent <-> child = related processes.

Suggestion for Nokia, could you join IEEE 1003 and add an asynchronous
PID-waiting syscall to POSIX? /me hides & runs.

Seriously though, adding the capability to the Linux kernel isn't all
that hard, but the problem is that it would "bloat" each task structure
with at lest one pointer (list-head), in a similar way that the process
accounting support does. Hence, it is not free (resource wise) to
implement. Other possibility would be using a global structure to keep
all the pid-trackers, but that's even worse solution (wrt scalability
across multiple logical CPUs, and locks and all that evil crufty stuff).


More information about the maemo-developers mailing list