I am using ps (specifically the psutil python library) to see a list of running processes on my linux machine. I want to deterimine which processes are running Go applications (that is, they are running Go code).
Below is the ps
output for a process that is written in Go. Is there anything that indicates that it is running Go code?
{'cmdline': ['./SampleMePlz'],
'connections': [connection(fd=3, family=10, type=1, laddr=('::', 8080), raddr=(), status='LISTEN')],
'cpu_affinity': [0, 1, 2, 3],
'cpu_percent': 0.0,
'cpu_times': cputimes(user=0.0, system=0.0),
'create_time': 1436474176.89,
'cwd': '/home/ben/gocode/src/SampleMePlz',
'exe': '/home/ben/gocode/src/SampleMePlz/SampleMePlz',
'ext_memory_info': meminfo(rss=4071424, vms=192684032, shared=3092480, text=3096576, lib=0, data=179523584, dirty=0),
'gids': group(real=5000, effective=5000, saved=5000),
'io_counters': io(read_count=12, write_count=0, read_bytes=4096, write_bytes=0),
'ionice': ionice(ioclass=0, value=4),
'memory_info': meminfo(rss=4071424, vms=192684032),
'memory_maps': [mmap(path='/lib/x86_64-linux-gnu/libpthread-2.15.so', rss=65536, size=2199552, pss=8192, shared_clean=57344, shared_dirty=0, private_clean=0, private_dirty=8192, referenced=65536, anonymous=8192, swap=0),
mmap(path='/lib/x86_64-linux-gnu/libc-2.15.so', rss=311296, size=3903488, pss=26624, shared_clean=286720, shared_dirty=0, private_clean=0, private_dirty=24576, referenced=311296, anonymous=24576, swap=0),
mmap(path='[stack]', rss=8192, size=139264, pss=8192, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=8192, referenced=8192, anonymous=8192, swap=0),
mmap(path='[anon]', rss=946176, size=179245056, pss=946176, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=946176, referenced=946176, anonymous=946176, swap=0),
mmap(path='/lib/x86_64-linux-gnu/ld-2.15.so', rss=122880, size=151552, pss=13312, shared_clean=110592, shared_dirty=0, private_clean=0, private_dirty=12288, referenced=122880, anonymous=12288, swap=0),
mmap(path='[vsyscall]', rss=0, size=4096, pss=0, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=0, referenced=0, anonymous=0, swap=0),
mmap(path='[heap]', rss=4096, size=135168, pss=4096, shared_clean=0, shared_dirty=0, private_clean=0, private_dirty=4096, referenced=4096, anonymous=4096, swap=0),
mmap(path='[vdso]', rss=4096, size=4096, pss=0, shared_clean=4096, shared_dirty=0, private_clean=0, private_dirty=0, referenced=4096, anonymous=0, swap=0),
mmap(path='/home/ben/gocode/src/SampleMePlz/SampleMePlz', rss=2908160, size=6905856, pss=2908160, shared_clean=0, shared_dirty=0, private_clean=2879488, private_dirty=28672, referenced=2908160, anonymous=28672, swap=0)],
'memory_percent': 0.025919821179310142,
'name': 'SampleMePlz',
'nice': 0,
'num_ctx_switches': amount(voluntary=15, involuntary=18),
'num_fds': 5,
'num_threads': 6,
'open_files': [],
'pid': 111252,
'ppid': 42061,
'status': 'sleeping',
'terminal': '/dev/pts/9',
'threads': [thread(id=111252, user_time=0.0, system_time=0.0),
thread(id=111253, user_time=0.0, system_time=0.0),
thread(id=111254, user_time=0.0, system_time=0.0),
thread(id=113972, user_time=0.0, system_time=0.0),
thread(id=113973, user_time=0.0, system_time=0.0),
thread(id=113974, user_time=0.0, system_time=0.0)],
'uids': user(real=3008, effective=3008, saved=3008),
'username': 'ben'}
The short answer is no. The code is compiled leaving no information about what language/compiler produced it. You can look for symptoms of a go-program, like references to your GOPATH or sub directories of it, but not much more.
In addition to @evanmcdonnal's answer, here's a (very, very) hacky solution:
strings /path/to/binary/from/ps/output | grep 'runtime.gogc'
Output:
<snip>
runtime.gogc runtime.gogc
runtime.gogc
<snip>
This of course relies on the binary format not changing or otherwise being obfuscated, which is not a good assumption to make long-term. I'm also assuming that runtime.gogc
exists across all Go binaries (it may not).
Note that it would be very rare for this to be useful information from an operational point of view.