ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

No, there is no such API.

No, there is no such API.

is there a way to get a list of URIs of the roscores that are running in a machine ?

you could probably put together a bit of Python which could do this, but it would be custom code and probably come down to just trying to connect to a nr of ports.

Every ROS Master is a stand-alone program. There is no central registry which keeps track of which are running or where.

Finally:

roscores that are running in a machine

It's not too common to have multiple masters running on a single machine actually.

No, there is no such API.

is there a way to get a list of URIs of the roscores that are running in a machine ?

you could probably put together a bit of Python which could do this, but it would be custom code and probably come down to just trying to connect to a nr of ports.

Every ROS Master is a stand-alone program. There is no central registry which keeps track of which are running or where.

Finally:

roscores that are running in a machine

It's not too common to have multiple masters running on a single machine actually.


Edit: what you could maybe look at is multimaster_fkie and the way it "discovers" running masters.

No, there is no such API.

is there a way to get a list of URIs of the roscores that are running in a machine ?

you could probably put together a bit of Python which could do this, but it would be custom code and probably come down to just trying to connect to a nr of ports.

Every ROS Master is a stand-alone program. There is no central registry which keeps track of which are running or where.

Finally:

roscores that are running in a machine

It's not too common to have multiple masters running on a single machine actually.


Edit: what you could maybe look at is multimaster_fkie and the way it "discovers" running masters.


Edit 2:

I'm looking for a workaround either with subprocess or linux commands in general that may give a list or roscore that are available and then to do some hardcoding for geting a list of the URIs but it's not clear how to find them. somehow there should be a way to find processes named roscore and get their information

On Linux you might be able to use a combination of pgrep roscore (which outputs the PIDs) and then netstat -antp and grep for the PID. Two "problems":

  1. with -p you will only see the PIDs/names of the processes your $USER started. To see all processes, you'd have to run netstat as root
  2. the PID pgrep roscore prints is not the PID which is associated with the XML-RPC port opened by roscore (ie: 11311)

You may need to do some additional work with ps or some other tool to find out the process group and filter on those PIDs.

Edit 3: Ok, so making a bunch of assumptions and using psutil in Python we can put something like this together:

#!/usr/bin/env python
import psutil

masters = [p for p in psutil.process_iter() if 'rosmaster' in p.name()]
for m in masters:
    listen_ports = [c.laddr for c in m.connections() if c.status == 'LISTEN']
    # assume there is only one tuple per process
    ip, port = listen_ports[0]
    print ("Master (pid: {}), URI: http://{}:{}".format(m.pid, ip, port))

Output on a machine running two masters (one on the standard port, the other on 11411):

Master (pid: 14735), URI: http://0.0.0.0:11311
Master (pid: 15018), URI: http://0.0.0.0:11411

The assumptions I'm making here:

  1. the process is actually called rosmaster
  2. it's listening on only a single port
  3. that port is the XML RPC port

Edit 2:

I'm looking for a workaround either with subprocess or linux commands in general that may give a list or roscore that are available and then to do some hardcoding for geting a list of the URIs but it's not clear how to find them. somehow there should be a way to find processes named roscore and get their information

On Linux you might be able to use a combination of pgrep roscore (which outputs the PIDs) and then netstat -antp and grep for the PID. Two "problems":

  1. with -p you will only see the PIDs/names of the processes your $USER started. To see all processes, you'd have to run netstat as root
  2. the PID pgrep roscore prints is not the PID which is associated with the XML-RPC port opened by roscore (ie: 11311)

You may need to do some additional work with ps or some other tool to find out the process group and filter on those PIDs.


Edit: what you could maybe look at is multimaster_fkie and the way it "discovers" running masters.


No, there is no such API.

is there a way to get a list of URIs of the roscores that are running in a machine ?

you could probably put together a bit of Python which could do this, but it would be custom code and probably come down to just trying to connect to a nr of ports.

Every ROS Master is a stand-alone program. There is no central registry which keeps track of which are running or where.

Finally:

roscores that are running in a machine

It's not too common to have multiple masters running on a single machine actually.


Edit: what you could maybe look at is multimaster_fkie and the way it "discovers" running masters.


Edit 2:

I'm looking for a workaround either with subprocess or linux commands in general that may give a list or roscore that are available and then to do some hardcoding for geting a list of the URIs but it's not clear how to find them. somehow there should be a way to find processes named roscore and get their information

On Linux you might be able to use a combination of pgrep roscore (which outputs the PIDs) and then netstat -antp and grep for the PID. Two "problems":

  1. with -p you will only see the PIDs/names of the processes your $USER started. To see all processes, you'd have to run netstat as root
  2. the PID pgrep roscore prints is not the PID which is associated with the XML-RPC port opened by roscore (ie: 11311)

You may need to do some additional work with ps or some other tool to find out the process group and filter on those PIDs.

Edit 3: Ok, so making a bunch of assumptions and using psutil in Python we can put something like this together:

#!/usr/bin/env python
import psutil

masters = [p for p in psutil.process_iter() if 'rosmaster' in p.name()]
for m in masters:
    listen_ports = [c.laddr for c in m.connections() if c.status == 'LISTEN']
    # assume there is only one tuple per process
    ip, port = listen_ports[0]
    print ("Master (pid: {}), URI: http://{}:{}".format(m.pid, ip, port))

Output on a machine running two masters (one on the standard port, the other on 11411):

Master (pid: 14735), URI: http://0.0.0.0:11311
Master (pid: 15018), URI: http://0.0.0.0:11411

The assumptions I'm making here:

  1. the process is actually called rosmaster
  2. it's listening on only a single port
  3. that port is the XML RPC port

I also don't know whether this will see roscores not started by your own $USER.


Edit 2:

I'm looking for a workaround either with subprocess or linux commands in general that may give a list or roscore that are available and then to do some hardcoding for geting a list of the URIs but it's not clear how to find them. somehow there should be a way to find processes named roscore and get their information

On Linux you might be able to use a combination of pgrep roscore (which outputs the PIDs) and then netstat -antp and grep for the PID. Two "problems":

  1. with -p you will only see the PIDs/names of the processes your $USER started. To see all processes, you'd have to run netstat as root
  2. the PID pgrep roscore prints is not the PID which is associated with the XML-RPC port opened by roscore (ie: 11311)

You may need to do some additional work with ps or some other tool to find out the process group and filter on those PIDs.


Edit: what you could maybe look at is multimaster_fkie and the way it "discovers" running masters.


No, there is no such API.

is there a way to get a list of URIs of the roscores that are running in a machine ?

you could probably put together a bit of Python which could do this, but it would be custom code and probably come down to just trying to connect to a nr of ports.

Every ROS Master is a stand-alone program. There is no central registry which keeps track of which are running or where.

Finally:

roscores that are running in a machine

It's not too common to have multiple masters running on a single machine actually.

Edit 3: Ok, so making a bunch of assumptions and using psutil in Python we can put something like this together:

#!/usr/bin/env python
import psutil

masters = [p for p in psutil.process_iter() if 'rosmaster' in p.name()]
for m in masters:
    listen_ports = [c.laddr for c in m.connections() if c.status == 'LISTEN']
    # assume there is only one tuple per process
    ip, port = listen_ports[0]
    print ("Master (pid: {}), URI: http://{}:{}".format(m.pid, ip, port))

Output on a machine running two masters (one on the standard port, the other on 11411):

Master (pid: 14735), URI: http://0.0.0.0:11311
Master (pid: 15018), URI: http://0.0.0.0:11411

The assumptions I'm making here:

  1. the process is actually called rosmaster
  2. it's listening on only a single port
  3. that port is the XML RPC port

I also don't know whether this will see roscores not started by your own $USER.

It sees them, but as expected, as $USER doesn't have the necessary rights, you get this:

Traceback (most recent call last):
File "list_rosmasters.py", line 7, in <module>
  listen_ports = [c.laddr for c in m.connections() if c.status == 'LISTEN']
File "/usr/lib/python2.7/dist-packages/psutil/__init__.py", line 1033, in connections
  return self._proc.connections(kind)
File "/usr/lib/python2.7/dist-packages/psutil/_pslinux.py", line 821, in wrapper
  raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=15557, name='rosmaster')

That would be the same limitation as running netstat without sudo.


Edit 2:

I'm looking for a workaround either with subprocess or linux commands in general that may give a list or roscore that are available and then to do some hardcoding for geting a list of the URIs but it's not clear how to find them. somehow there should be a way to find processes named roscore and get their information

On Linux you might be able to use a combination of pgrep roscore (which outputs the PIDs) and then netstat -antp and grep for the PID. Two "problems":

  1. with -p you will only see the PIDs/names of the processes your $USER started. To see all processes, you'd have to run netstat as root
  2. the PID pgrep roscore prints is not the PID which is associated with the XML-RPC port opened by roscore (ie: 11311)

You may need to do some additional work with ps or some other tool to find out the process group and filter on those PIDs.


Edit: what you could maybe look at is multimaster_fkie and the way it "discovers" running masters.


No, there is no such API.

is there a way to get a list of URIs of the roscores that are running in a machine ?

you could probably put together a bit of Python which could do this, but it would be custom code and probably come down to just trying to connect to a nr of ports.

Every ROS Master is a stand-alone program. There is no central registry which keeps track of which are running or where.

Finally:

roscores that are running in a machine

It's not too common to have multiple masters running on a single machine actually.

Edit 3: Ok, so making a bunch of assumptions and using psutil in Python we can put something like this together:

#!/usr/bin/env python
import psutil

masters = [p for p in psutil.process_iter() if 'rosmaster' in p.name()]
for m in masters:
    listen_ports # assume there is only one connection per process which is LISTENing
    ip, port = [c.laddr for c in m.connections() if c.status == 'LISTEN']
    # assume there is only one tuple per process
    ip, port = listen_ports[0]
'LISTEN'][0]
    print ("Master (pid: {}), URI: http://{}:{}".format(m.pid, ip, port))

Output on a machine running two masters (one on the standard port, the other on 11411):

Master (pid: 14735), URI: http://0.0.0.0:11311
Master (pid: 15018), URI: http://0.0.0.0:11411

The assumptions I'm making here:

  1. the process is actually called rosmaster
  2. it's listening on only a single port
  3. that port is the XML RPC port

I also don't know whether this will see roscores not started by your own $USER.

It sees them, but as expected, as $USER doesn't have the necessary rights, you get this:

Traceback (most recent call last):
File "list_rosmasters.py", line 7, in <module>
  listen_ports = [c.laddr for c in m.connections() if c.status == 'LISTEN']
File "/usr/lib/python2.7/dist-packages/psutil/__init__.py", line 1033, in connections
  return self._proc.connections(kind)
File "/usr/lib/python2.7/dist-packages/psutil/_pslinux.py", line 821, in wrapper
  raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=15557, name='rosmaster')

That would be the same limitation as running netstat without sudo.


Edit 2:

I'm looking for a workaround either with subprocess or linux commands in general that may give a list or roscore that are available and then to do some hardcoding for geting a list of the URIs but it's not clear how to find them. somehow there should be a way to find processes named roscore and get their information

On Linux you might be able to use a combination of pgrep roscore (which outputs the PIDs) and then netstat -antp and grep for the PID. Two "problems":

  1. with -p you will only see the PIDs/names of the processes your $USER started. To see all processes, you'd have to run netstat as root
  2. the PID pgrep roscore prints is not the PID which is associated with the XML-RPC port opened by roscore (ie: 11311)

You may need to do some additional work with ps or some other tool to find out the process group and filter on those PIDs.


Edit: what you could maybe look at is multimaster_fkie and the way it "discovers" running masters.


No, there is no such API.

is there a way to get a list of URIs of the roscores that are running in a machine ?

you could probably put together a bit of Python which could do this, but it would be custom code and probably come down to just trying to connect to a nr of ports.

Every ROS Master is a stand-alone program. There is no central registry which keeps track of which are running or where.

Finally:

roscores that are running in a machine

It's not too common to have multiple masters running on a single machine actually.

Edit 3: Ok, so making a bunch of assumptions and using psutil in Python we can put something like this together:

#!/usr/bin/env python
import psutil

masters = [p for p in psutil.process_iter() if 'rosmaster' in p.name()]
for m in masters:
    # assume there is only one connection per process which is LISTENing
    # TODO: make this more robust, do some checking, etc
    ip, port = [c.laddr for c in m.connections() if c.status == 'LISTEN'][0]
    print ("Master (pid: {}), URI: http://{}:{}".format(m.pid, ip, port))

Output on a machine running two masters (one on the standard port, the other on 11411):

Master (pid: 14735), URI: http://0.0.0.0:11311
Master (pid: 15018), URI: http://0.0.0.0:11411

The assumptions I'm making here:

  1. the process is actually called rosmaster
  2. it's listening on only a single port
  3. that port is the XML RPC port

I also don't know whether this will see roscores not started by your own $USER.

It sees them, but as expected, as $USER doesn't have the necessary rights, you get this:

Traceback (most recent call last):
File "list_rosmasters.py", line 7, in <module>
  listen_ports = [c.laddr for c in m.connections() if c.status == 'LISTEN']
File "/usr/lib/python2.7/dist-packages/psutil/__init__.py", line 1033, in connections
  return self._proc.connections(kind)
File "/usr/lib/python2.7/dist-packages/psutil/_pslinux.py", line 821, in wrapper
  raise AccessDenied(self.pid, self._name)
psutil.AccessDenied: psutil.AccessDenied (pid=15557, name='rosmaster')

That would be the same limitation as running netstat without sudo.


Edit 2:

I'm looking for a workaround either with subprocess or linux commands in general that may give a list or roscore that are available and then to do some hardcoding for geting a list of the URIs but it's not clear how to find them. somehow there should be a way to find processes named roscore and get their information

On Linux you might be able to use a combination of pgrep roscore (which outputs the PIDs) and then netstat -antp and grep for the PID. Two "problems":

  1. with -p you will only see the PIDs/names of the processes your $USER started. To see all processes, you'd have to run netstat as root
  2. the PID pgrep roscore prints is not the PID which is associated with the XML-RPC port opened by roscore (ie: 11311)

You may need to do some additional work with ps or some other tool to find out the process group and filter on those PIDs.


Edit: what you could maybe look at is multimaster_fkie and the way it "discovers" running masters.


No, there is no such API.

is there a way to get a list of URIs of the roscores that are running in a machine ?

you could probably put together a bit of Python which could do this, but it would be custom code and probably come down to just trying to connect to a nr of ports.

Every ROS Master is a stand-alone program. There is no central registry which keeps track of which are running or where.

Finally:

roscores that are running in a machine

It's not too common to have multiple masters running on a single machine actually.