[Gambas-user] R: My programm name of process

Bruce bbruen at ...2308...
Fri Oct 5 17:10:50 CEST 2012


On Fri, 2012-10-05 at 11:20 +0100, Ru Vuott wrote:
> ...this is a possible way:
> 
> ********************
> Public Sub Button1_Click()
> 
>   Dim s1, s2, pid As String
>   
>   
>   s1 = InputBox("Insert the program name (<B>without</b> its extension .gambas):")
>   
>   
>   For Each pid In Dir("/proc")
> 
>     If Exist("/proc/" & pid & "/cmdline") Then
>     
>       s2 = File.Load("/proc/" & pid & "/cmdline")
> 
>       If s2 Like "*" & s1 & ".gambas*" Then
>         Shell "kill " & pid
>         Exit
>       Endif
>     
>     Endif
>     
>   Next
> 
> End
> 
> *******************
> 
> bye
> vuotttt
> 
> 
> 
Even that is risky, because if you have more than one instance of the
same executable running .. you will send a SIGTERM to all of them.

It is really much better to use a properly structured signal handler
within the project that can respond to SIGs and react appropriately and
if required close down in an orderly manner.  Note that this not a
simple answer, even postgresql to date still has the warning "don't kill
the postmaster!"

( Hi Benoit :-) hint hint gb.signal hint hint...)


Oh! and a final comment generally within this thread.   (IMO)

Never try to "kill" other processes from within a process.  Much too
messy and they may come back as zombies and do the same thing to you.
"kill"ing is for humans to do, not programs (there could be a corollary
of one of Asimovs laws there, possibly?) 

B





More information about the User mailing list