Skip to content

Commit

Permalink
Change scripts which use "pgrep" to avoid PID 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
rongguodong authored and storypku committed Sep 3, 2020
1 parent 82e64a9 commit e58c985
Show file tree
Hide file tree
Showing 21 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion scripts/apollo_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function decide_task_dir() {
function is_stopped_customized_path() {
MODULE_PATH=$1
MODULE=$2
NUM_PROCESSES="$(pgrep -c -f "modules/${MODULE_PATH}/launch/${MODULE}.launch")"
NUM_PROCESSES="$(pgrep -f "modules/${MODULE_PATH}/launch/${MODULE}.launch" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
return 1
else
Expand Down
2 changes: 1 addition & 1 deletion scripts/camera.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ source "${DIR}/apollo_base.sh"
function start() {
LOG="${APOLLO_ROOT_DIR}/data/log/camera.out"
CMD="cyber_launch start /apollo/modules/drivers/camera/launch/camera.launch"
NUM_PROCESSES="$(pgrep -c -f "modules/drivers/camera/dag/camera.dag")"
NUM_PROCESSES="$(pgrep -f "modules/drivers/camera/dag/camera.dag" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
eval "nohup ${CMD} </dev/null >${LOG} 2>&1 &"
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/camera_and_video.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ source "${DIR}/apollo_base.sh"
function start() {
LOG="${APOLLO_ROOT_DIR}/data/log/camera_and_video.out"
CMD="cyber_launch start /apollo/modules/drivers/camera/launch/camera_and_video.launch"
NUM_PROCESSES=$(expr "$(pgrep -c -f "modules/drivers/camera/dag/camera.dag")" + "$(pgrep -c -f "modules/drivers/video/dag/video.dag")")
NUM_PROCESSES=$(expr "$(pgrep -f "modules/drivers/camera/dag/camera.dag" | grep -cv '^1$')" + "$(pgrep -f "modules/drivers/video/dag/video.dag" | grep -cv '^1$')")
if [ "${NUM_PROCESSES}" -eq 0 ]; then
eval "nohup ${CMD} </dev/null >${LOG} 2>&1 &"
fi
Expand Down
6 changes: 3 additions & 3 deletions scripts/lidar_calibration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function start_record() {
MODULE="republish_msg"

# check if the module has started
NUM_PROCESSES="$(pgrep -c -f "modules/calibration/${MODULE}")"
NUM_PROCESSES="$(pgrep -f "modules/calibration/${MODULE}" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
eval "nohup ${APOLLO_BIN_PREFIX}/modules/calibration/${MODULE}/${MODULE} \
--flagfile=${APOLLO_ROOT_DIR}/modules/calibration/${MODULE}/conf/${MODULE}.conf \
Expand All @@ -89,7 +89,7 @@ function start_record() {
fi

# start to record lidar calibration data
NUM_PROCESSES="$(pgrep -c -f "rosbag record")"
NUM_PROCESSES="$(pgrep -f "rosbag record" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
nohup rosbag record -b 2048 -O lidar_calib.bag \
/apollo/sensor/gnss/ins_stat \
Expand Down Expand Up @@ -123,7 +123,7 @@ function start_check_extrin() {
MODULE="lidar_ex_checker"

# check if the module has started
NUM_PROCESSES="$(pgrep -c -f "modules/calibration/${MODULE}")"
NUM_PROCESSES="$(pgrep -f "modules/calibration/${MODULE}" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
echo "Start program, Ctrl+C to exit."
eval "${APOLLO_BIN_PREFIX}/modules/calibration/${MODULE}/${MODULE} \
Expand Down
2 changes: 1 addition & 1 deletion scripts/navigation_usb_camera.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ source "${DIR}/apollo_base.sh"
function start() {
LOG="${APOLLO_ROOT_DIR}/data/log/usb_cam.out"
CMD="roslaunch usb_cam start_obstacle_camera.launch"
NUM_PROCESSES="$(pgrep -c -f "camera_nodelet_manager")"
NUM_PROCESSES="$(pgrep -f "camera_nodelet_manager" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
eval "nohup ${CMD} </dev/null >${LOG} 2>&1 &"
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/record_bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def record_task(self, disk, topics, is_small_topic=False):
@staticmethod
def is_running():
"""Test if the given process running."""
_, stdout, _ = shell_cmd('pgrep -c -f "cyber_recorder record"', False)
_, stdout, _ = shell_cmd('pgrep -f "cyber_recorder record" | grep -cv '^1$'', False)
# If stdout is the pgrep command itself, no such process is running.
return stdout.strip() != '1' if stdout else False

Expand Down
2 changes: 1 addition & 1 deletion scripts/record_bag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function start() {
# Start recording.
record_bag_env_log
LOG="/tmp/apollo_record.out"
NUM_PROCESSES="$(pgrep -c -f "cyber_recorder record")"
NUM_PROCESSES="$(pgrep -f "cyber_recorder record" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
nohup cyber_recorder record -a -i 60 -m 2048 /apollo/sensor/camera/obstacle/front_6mm \
/apollo/sensor/conti_radar \
Expand Down
2 changes: 1 addition & 1 deletion scripts/record_bag_local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function start() {
# Start recording.
record_bag_env_log
LOG="/tmp/apollo_record.out"
NUM_PROCESSES="$(pgrep -c -f "rosbag record")"
NUM_PROCESSES="$(pgrep -f "rosbag record" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
nohup rosbag record --split --duration=1m -b 2048 \
/apollo/sensor/gnss/best_pose \
Expand Down
2 changes: 1 addition & 1 deletion scripts/record_bag_navigation_perception.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function start() {
# Start recording.
record_bag_env_log
LOG="/tmp/apollo_record.out"
NUM_PROCESSES="$(pgrep -c -f "rosbag record")"
NUM_PROCESSES="$(pgrep -f "rosbag record" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
nohup rosbag record --split --duration=1m -b 2048 \
/apollo/sensor/camera/obstacle/front_6mm \
Expand Down
2 changes: 1 addition & 1 deletion scripts/record_bag_pnc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function start() {
# Start recording.
record_bag_env_log
LOG="/tmp/apollo_record.out"
NUM_PROCESSES="$(pgrep -c -f "rosbag record")"
NUM_PROCESSES="$(pgrep -f "rosbag record" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
nohup rosbag record --split --duration=10m -b 2048 \
/apollo/sensor/conti_radar \
Expand Down
2 changes: 1 addition & 1 deletion scripts/record_bag_sensor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function start() {
# Start recording.
record_bag_env_log
LOG="/tmp/apollo_record.out"
NUM_PROCESSES="$(pgrep -c -f "rosbag record")"
NUM_PROCESSES="$(pgrep -f "rosbag record" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
nohup rosbag record --split --duration=1m -b 2048 \
/apollo/sensor/camera/traffic/image_short \
Expand Down
2 changes: 1 addition & 1 deletion scripts/record_map_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def record_task(self, disk, topics):
@staticmethod
def is_running():
"""Test if the given process running."""
_, stdout, _ = shell_cmd('pgrep -c -f "cyber_recorder record"', False)
_, stdout, _ = shell_cmd('pgrep -f "cyber_recorder record" | grep -cv '^1$'', False)
# If stdout is the pgrep command itself, no such process is running.
return stdout.strip() != '1' if stdout else False

Expand Down
2 changes: 1 addition & 1 deletion scripts/record_map_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function start() {
# Start recording.
record_bag_env_log
LOG="/tmp/apollo_record.out"
NUM_PROCESSES="$(pgrep -c -f "rosbag record")"
NUM_PROCESSES="$(pgrep -f "rosbag record" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
nohup rosbag record --split --duration=1m -b 2048 \
/apollo/sensor/camera/traffic/image_long \
Expand Down
2 changes: 1 addition & 1 deletion scripts/record_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def record_task(self, disk):
@staticmethod
def is_running():
"""Test if the given process running."""
_, stdout, _ = shell_cmd('pgrep -c -f "smart_recorder"', False)
_, stdout, _ = shell_cmd('pgrep -f "smart_recorder" | grep -cv '^1$'', False)
# If stdout is the pgrep command itself, no such process is running.
return stdout.strip() != '1' if stdout else False

Expand Down
2 changes: 1 addition & 1 deletion scripts/rtk_player.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function setup() {
}

function start() {
NUM_PROCESSES="$(pgrep -c -f "record_play/rtk_player")"
NUM_PROCESSES="$(pgrep -f "record_play/rtk_player" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -ne 0 ]; then
pkill -SIGKILL -f rtk_player
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/rtk_recorder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function start() {
cp data/log/garage.csv data/log/garage-${TIME}.csv
fi

NUM_PROCESSES="$(pgrep -c -f "record_play/rtk_recorder")"
NUM_PROCESSES="$(pgrep -f "record_play/rtk_recorder" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
${TOP_DIR}/bazel-bin/modules/tools/record_play/rtk_recorder
fi
Expand Down
10 changes: 5 additions & 5 deletions scripts/sensor_calibration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function calibrate_camera_camera() {
MODULE="camera_camera_calibrator"

# check if the module has started
NUM_PROCESSES="$(pgrep -c -f "${MODULE}")"
NUM_PROCESSES="$(pgrep -f "${MODULE}" | grep -cv '^1$')"

if [ "${NUM_PROCESSES}" -eq 0 ]; then
echo "Start to calibrate Camera-Camera extrinsics, Ctrl+C to exit."
Expand All @@ -41,7 +41,7 @@ function calibrate_lidar_camera() {
MODULE="lidar_camera_calibrator"

# check if the module has started
NUM_PROCESSES="$(pgrep -c -f "${MODULE}")"
NUM_PROCESSES="$(pgrep -f "${MODULE}" | grep -cv '^1$')"

if [ "${NUM_PROCESSES}" -eq 0 ]; then
echo "Start to calibrate LiDAR-Camera extrinsics, Ctrl+C to exit."
Expand All @@ -56,7 +56,7 @@ function calibrate_radar_camera() {
MODULE="radar_camera_calibrator"

# check if the module has started
NUM_PROCESSES="$(pgrep -c -f "${MODULE}")"
NUM_PROCESSES="$(pgrep -f "${MODULE}" | grep -cv '^1$')"

if [ "${NUM_PROCESSES}" -eq 0 ]; then
echo "Start to calibrate Radar-Camera extrinsics, Ctrl+C to exit."
Expand All @@ -71,7 +71,7 @@ function visualize_radar_lidar() {
MODULE="radar_lidar_visualizer"

# check if the module has started
NUM_PROCESSES="$(pgrep -c -f "${MODULE}")"
NUM_PROCESSES="$(pgrep -f "${MODULE}" | grep -cv '^1$')"

if [ "${NUM_PROCESSES}" -eq 0 ]; then
echo "Visualize Radar and LiDAR data, Ctrl+C to exit."
Expand All @@ -86,7 +86,7 @@ function calibrate_imu_vehicle() {
MODULE="imu_car_calibrator"

# check if the module has started
NUM_PROCESSES="$(pgrep -c -f "${MODULE}")"
NUM_PROCESSES="$(pgrep -f "${MODULE}" | grep -cv '^1$')"

if [ "${NUM_PROCESSES}" -eq 0 ]; then
echo "Start to calibrate Imu-Vehicle extrinsics, Ctrl+C to exit."
Expand Down
2 changes: 1 addition & 1 deletion scripts/transform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ source "${DIR}/scripts/apollo_base.sh"
function start() {
LOG="${APOLLO_ROOT_DIR}/data/log/transform.out"
CMD="cyber_launch start /apollo/modules/transform/launch/static_transform.launch"
NUM_PROCESSES="$(pgrep -c -f "modules/transform/dag/static_transform.dag")"
NUM_PROCESSES="$(pgrep -f "modules/transform/dag/static_transform.dag" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
eval "nohup ${CMD} </dev/null >${LOG} 2>&1 &"
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/velodyne.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ source "${DIR}/scripts/apollo_base.sh"
function start() {
LOG="${APOLLO_ROOT_DIR}/data/log/velodyne.out"
CMD="cyber_launch start /apollo/modules/drivers/velodyne/launch/velodyne.launch"
NUM_PROCESSES="$(pgrep -c -f "/apollo/modules/drivers/velodyne/dag/velodyne.dag")"
NUM_PROCESSES="$(pgrep -f "/apollo/modules/drivers/velodyne/dag/velodyne.dag" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
eval "nohup ${CMD} </dev/null >${LOG} 2>&1 &"
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/velodyne_16.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ source "${DIR}/scripts/apollo_base.sh"
function start() {
LOG="${APOLLO_ROOT_DIR}/data/log/velodyne16.out"
CMD="roslaunch velodyne start_velodyne_16.launch"
NUM_PROCESSES="$(pgrep -c -f "sensor_velodyne16")"
NUM_PROCESSES="$(pgrep -f "sensor_velodyne16" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
eval "nohup ${CMD} </dev/null >${LOG} 2>&1 &"
fi
Expand Down
2 changes: 1 addition & 1 deletion scripts/velodyne_for_map_data_colloector.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ source "${DIR}/scripts/apollo_base.sh"
function start() {
LOG="${APOLLO_ROOT_DIR}/data/log/velodyne.out"
CMD="roslaunch velodyne start_velodyne_for_map_data_collector.launch"
NUM_PROCESSES="$(pgrep -c -f "velodyne_nodelet_manager")"
NUM_PROCESSES="$(pgrep -f "velodyne_nodelet_manager" | grep -cv '^1$')"
if [ "${NUM_PROCESSES}" -eq 0 ]; then
eval "nohup ${CMD} </dev/null >${LOG} 2>&1 &"
fi
Expand Down

0 comments on commit e58c985

Please sign in to comment.