ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Similar to sergey_alexandrov answer, but using psutils python module as highlight on stackoverflow : http://stackoverflow.com/questions/3332043/obtaining-pid-of-child-process
def terminate_process_and_children(p): import psutil process = psutil.Process(p.pid) for sub_process in process.get_children(recursive=True): sub_process.send_signal(signal.SIGINT) p.wait() # we wait for children to terminate p.terminate()
def main(): dir_save_bagfile = '/tmp/' rosbag_process = subprocess.Popen('rosbag record -a -j -o {}'.format("my_rosbag_prefis"), stdin=subprocess.PIPE, shell=True, cwd=dir_save_bagfile) terminate_process_and_children(rosbag_process)
2 | No.2 Revision |
Similar to sergey_alexandrov answer, but using psutils python module as highlight on stackoverflow : http://stackoverflow.com/questions/3332043/obtaining-pid-of-child-process
def terminate_process_and_children(p):