Re: [Banshee-List] "Banshee is already running"



Strange.

When I wrote that code for fallback instance detection, I was working
under the assumption that only one parent "banshee" process would show
up in that check, which indeed was and should still be the case. This
check still works for me.

First thing to note though as this should only iterate _mono_ processes,
not system processes. However, it should not matter how many threads a
process has running. 

I've attached a simple little test program that spawns a bunch of
threads and does process name/id-based instance detection.

Below are my results, which are what I expected. Would you mind
building/running/pasting your results?

Cheers,
--Aaron

Instance A:

aaron linux:~/Desktop$ mono proctest.exe
Main thread is sleeping for 10 seconds
  Spawning Thread 0
     Thread 0 says hi!
  Spawning Thread 1
     Thread 1 says hi!
     Thread 0 says hi!
Main thread continues
  Spawning Thread 2
     Thread 2 says hi!
     Thread 0 says hi!
     Thread 1 says hi!
proctest (21865)
Tomboy (6058)
MonoDevelop (20868)
  Spawning Thread 3
     Thread 0 says hi!
     Thread 1 says hi!
     Thread 2 says hi!
     Thread 3 says hi!
  Spawning Thread 4
     Thread 0 says hi!
     Thread 1 says hi!
     Thread 2 says hi!
     Thread 4 says hi!
     Thread 3 says hi!
     Thread 0 says hi!

Instance B:

aaron linux:~/Desktop$ mono proctest.exe
Main thread is sleeping for 10 seconds
  Spawning Thread 0
     Thread 0 says hi!
  Spawning Thread 1
     Thread 1 says hi!
     Thread 0 says hi!
Main thread continues
  Spawning Thread 2
     Thread 1 says hi!
     Thread 0 says hi!
     Thread 2 says hi!
An instance is already running



On Wed, 2006-01-18 at 21:39 -0600, Russ Brown wrote:
> How silly of me not to think of that.
> 
> I tried the strace but saw no mention of any lock files.
> 
> I tried downgrading and that fixed the problem. Interesting.
> 
> So, I tried the source. It appears that banshee runs through all
> running processes and compares names with process IDs(Main.cs around line 104). I added some
> additional debug output to show me what these values are:
> 
> Console.WriteLine("Current process name: " +
> current_process.ProcessName);
> Console.WriteLine("Process name        : " + process.ProcessName);
> Console.WriteLine("Current process ID  : " + current_process.Id);
> Console.WriteLine("Process ID          : " + process.Id);
> System.Threading.Thread.Sleep(Timeout.Infinite);
> 
> The output for the first run was:
> 
> $ banshee
> 
> Banshee is already running. If you were trying to control the already
> running instance of Banshee, D-Bus must be enabled. Banshee could not
> connect to your D-Bus Session Bus.
> Current process name: banshee
> Process name        : banshee
> Current process ID  : 701
> Process ID          : 9328
> 
> While this was running I saw that process ID 701 was indeed banshee (in 
> fact there were three of them with the same ID, most likely threads):
> 
> /bin/mono --debug /usr/lib/banshee/banshee.exe
> 
> Process ID 9328 is odd because according to ps it is:
> 
> /usr/bin/xfce4-session
> 
> The interesting thing is, neither of these processes are called 'banshee'
> from what I can see. Where does process.ProcessName gets its value
> from? The mono documentation for that method is incomplete.
> 
> The good news is that if I just bypass this check completely I'm able
> to run banshee without any showstoppers(*). My knowledge of these Mono
> classes is limited to what I just leaned just now. If anyone else can
> suggest any further debugging I can do, I'll be happy to try it.
> 
> (*) When starting up I get the following error, but I'm able to see my
> ipod anyway. Weird.
> 
> (Could not connect to D-Bus) - D-Bus support will be disabled for this
> instance: Object reference not set to an instance of an object
> 
> On Wed, 18 Jan 2006 16:07:10 -0500
> Peter Colijn <pcolijn gmail com> wrote:
> 
> > I'm not a Banshee devel, but one thing you could try is stracing
> > banshee when it starts up, to see if it's determining whether another
> > Banshee is running by looking for some file somehwere. If it is
> > checking that way (and you are really sure Banshee isn't running), you
> > can just remove that file. You could also grep the source for "Banshee
> > is already running" and see what it's doing that way.
> > 
> > Have fun,
> > 
> > Peter
> > 
> > On 1/18/06, Russ Brown <pickscrape gmail com> wrote:
> > > I've just upgraded to 0.10.4, and now find myself completely unable
> > > to launch banshee at all.
> > >
> > > The error I get is:
> > >
> > > "Banshee is already running. If you were trying to control the
> > > already running instance of Banshee, D-Bus must be enabled. Banshee
> > > could not connect to your D-Bus Session Bus."
> > >
> > > Well, Banshee is definitely not already running. ps -eaf shows that
> > > neither 'banshee' or 'mono' is running at all.
> > >
> > > DBus is enabled. I've restarted it and dbus processes are running.
> > > Furthermore, if I run the ipod utility and plug my ipod in, I see
> > > notification of the device being found, so I know that DBus is
> > > working.
> > >
> > > Finally, I tried launching banshee with dbus-launch, which produced
> > > the same error message.
> > >
> > > Any ideas?
> > >
> > > Thanks.
> > >
> > > --
> > >
> > > Russ
> > > _______________________________________________
> > > Banshee-list mailing list
> > > Banshee-list gnome org
> > > http://mail.gnome.org/mailman/listinfo/banshee-list
> > >
> 
> 
using System;
using System.Threading;
using System.Diagnostics;

public static class ProcessTest
{
    private static Process current_process = Process.GetCurrentProcess();

    public static void Main()
    {
        SpawnThreads();
    
        Console.WriteLine("Main thread is sleeping for 10 seconds");
        Thread.Sleep(10000);
        Console.WriteLine("Main thread continues");
    
        if(DetectInstance()) {
            Console.WriteLine("An instance is already running");
            Environment.Exit(1);
        }
        
        DumpProcesses();
    }
    
    private static void SpawnThreads()
    {
        Thread spawner = new Thread(delegate {
            for(int i = 0; i < 5; i++) {
                Console.WriteLine("  Spawning Thread {0}", i);
                
                ThreadPool.QueueUserWorkItem(delegate (object o) {
                    while(true) {
                        Console.WriteLine("     Thread {0} says hi!", (int)o);
                        Thread.Sleep(5000);
                    }
                }, i);
                
                Thread.Sleep(5000);
            }
        });
        
        spawner.Start();
    }
    
    private static bool DetectInstance()
    {
        foreach(Process process in Process.GetProcesses()) {
            if(process.ProcessName == current_process.ProcessName 
                && process.Id != current_process.Id) {
                return true;
            }
        }
        
        return false;
    }
    
    private static void DumpProcesses()
    {
        foreach(Process process in Process.GetProcesses()) {
            Console.WriteLine("{0} ({1})", process.ProcessName, process.Id);
        }
    }
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]