From 1bf1a4d5e94600c67f22c814c899da7398d80d54 Mon Sep 17 00:00:00 2001 From: Bob Lantz <rlantz@cs.stanford.edu> Date: Fri, 22 Mar 2013 18:33:37 -0700 Subject: [PATCH] Tag node bash processes and add attach script Try invoking bash processes with -s mininet:host, for easy identification of hosts. This enables easy attachment using the util/m script. closes #121 --- mininet/clean.py | 5 ++++- mininet/node.py | 3 ++- util/m | 30 ++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100755 util/m diff --git a/mininet/clean.py b/mininet/clean.py index 56ff6ffa..07b4d6b9 100755 --- a/mininet/clean.py +++ b/mininet/clean.py @@ -27,12 +27,15 @@ def cleanup(): info("*** Removing excess controllers/ofprotocols/ofdatapaths/pings/noxes" "\n") zombies = 'controller ofprotocol ofdatapath ping nox_core lt-nox_core ' - zombies += 'ovs-openflowd udpbwtest' + zombies += 'ovs-openflowd udpbwtest mnexec' # Note: real zombie processes can't actually be killed, since they # are already (un)dead. Then again, # you can't connect to them either, so they're mostly harmless. sh( 'killall -9 ' + zombies + ' 2> /dev/null' ) + # And kill off sudo mnexec + sh( 'pkill -9 -f "sudo mnexec"') + info( "*** Removing junk from /tmp\n" ) sh( 'rm -f /tmp/vconn* /tmp/vlogs* /tmp/*.out /tmp/*.log' ) diff --git a/mininet/node.py b/mininet/node.py index 47790221..6275f0cb 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -118,7 +118,8 @@ def startShell( self ): if self.inNamespace: opts += 'n' # bash -m: enable job control - cmd = [ 'mnexec', opts, 'bash', '-m' ] + # -s: pass $* to shell, and make process easy to find in ps + cmd = [ 'mnexec', opts, 'bash', '-ms', 'mininet:' + self.name ] self.shell = Popen( cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True ) self.stdin = self.shell.stdin diff --git a/util/m b/util/m new file mode 100755 index 00000000..9757c2ce --- /dev/null +++ b/util/m @@ -0,0 +1,30 @@ +#!/bin/bash + +# Attach to a Mininet host and run a command + +if [ -z $1 ]; then + echo "usage: $0 host cmd [args...]" + exit 1 +else + host=$1 +fi + +pid=`pgrep -f mininet:$host` +if [ "$pid" == "" ]; then + echo "Could not find Mininet host $host" + exit 2 +fi + +if [ -z $2 ]; then + cmd='bash' +else + shift + cmd=$* +fi + +cgroup=/sys/fs/cgroup/cpu/$host +if [ -d "$cgroup" ]; then + cg="-g $host" +fi + +exec sudo mnexec -a $pid $cg $cmd -- GitLab