remove_lxc_pid() { # in : list of pid # out : list of pid without lxc process # if kernel don't have cgroup, return all pids if [[ ! -f /proc/self/cgroup ]] ; then echo -n $@ return fi local CGROUP=$(cat /proc/self/cgroup 2> /dev/null) # if self cgroup info is not ended by :/ # we are inside lxc, return all pids if [[ ! ${CGROUP:(-2)} = ':/' ]] ; then echo -n $@ return fi local PID='' local NOLXC='' # Loop on all pids for PID in $@ do # if PID don't existe : go next # [[ -d /proc/${PID} ]] || continue # CGROUP=$(cat /proc/${PID}/cgroup) # Get info from cgroup CGROUP=$(cat /proc/${PID}/cgroup 2> /dev/null) # if cgroup info is ended by :/ is not a lxc process # cgroup lxc process is ended by lxc name [[ ${CGROUP:(-2)} = ':/' ]] && NOLXC="$PID $NOLXC" done # Remove ending space echo -n ${NOLXC/% } } pidof() { echo $(remove_lxc_pid $(/bin/pidof $@)) }