diff --git a/mininet/net.py b/mininet/net.py index a4477d37aa03c0b76823b303698949d4bef82bc9..8a6acdcc3a71a3546d65d96329053680a9880a2b 100755 --- a/mininet/net.py +++ b/mininet/net.py @@ -740,7 +740,7 @@ def runCpuLimitTest( self, cpu, duration=5 ): sleep( 1 ) outputs.append( quietRun( cmd ).strip() ) for h in hosts: - h.cmd( 'kill %1' ) + h.cmd( 'kill $!' ) cpu_fractions = [] for test_output in outputs: # Split by line. Ignore first line, which looks like this: diff --git a/mininet/node.py b/mininet/node.py index 475d82b6451207ee56aa66e6b45a0c78074dfe66..20b18aae1b47ff7ff6c2cfe1572615c64201c7b4 100644 --- a/mininet/node.py +++ b/mininet/node.py @@ -160,6 +160,7 @@ def startShell( self ): self.pollOut.poll() self.waiting = False self.cmd( 'stty -echo' ) + self.cmd( 'set +m' ) def cleanup( self ): "Help python collect its garbage." @@ -238,12 +239,12 @@ def sendCmd( self, *args, **kwargs ): # Replace empty commands with something harmless cmd = 'echo -n' self.lastCmd = cmd - if printPid and not isShellBuiltin( cmd ): - if len( cmd ) > 0 and cmd[ -1 ] == '&': - # print ^A{pid}\n so monitor() can set lastPid - cmd += ' printf "\\001%d\n" $! \n' - else: - cmd = 'mnexec -p ' + cmd + # if a builtin command is backgrounded, it still yields a PID + if len( cmd ) > 0 and cmd[ -1 ] == '&': + # print ^A{pid}\n so monitor() can set lastPid + cmd += ' printf "\\001%d\\012" $! ' + elif printPid and not isShellBuiltin( cmd ): + cmd = 'mnexec -p ' + cmd self.write( cmd + '\n' ) self.lastPid = None self.waiting = True @@ -258,9 +259,13 @@ def monitor( self, timeoutms=None, findPid=True ): timeoutms: timeout in ms or None to wait indefinitely.""" self.waitReadable( timeoutms ) data = self.read( 1024 ) + pidre = r'\[\d+\] \d+\r\n' # Look for PID marker = chr( 1 ) + r'\d+\r\n' if findPid and chr( 1 ) in data: + # suppress the job and PID of a backgrounded command + if re.findall( pidre, data ): + data = re.sub( pidre, '', data ) # Marker can be read in chunks; continue until all of it is read while not re.findall( marker, data ): data += self.read( 1024 ) @@ -1264,7 +1269,7 @@ def start( self ): if self.cdir is not None: self.cmd( 'cd ' + self.cdir ) self.cmd( self.command + ' ' + self.cargs % self.port + - ' 1>' + cout + ' 2>' + cout + '&' ) + ' 1>' + cout + ' 2>' + cout + ' &' ) self.execed = False def stop( self ):