You never mentioned which OS. This is for a /proc based system.
A very roundabout manner. Use readlink on all pids, then extract the user based on the pids from the ps listing.
Assumes a exact match between the directory to detect and the result of readlink.
Code:
[/tmp]$ cat detect.ksh
#! /bin/ksh
DIR=/dir/to/detect
cd /proc
for file in `ls -1`
do
if [ -d "$file" ] ; then
cd "$file"
FIND=$(readlink -f cwd)
if [[ "$FIND" == "$DIR" ]] ; then
PS_ALL="$PS_ALL $file"
fi ;
cd ..
fi ;
done
echo "$PS_ALL"
# From the ps listing, get the user id from the pid
for pid in "$PS_ALL"
do
ps -o user -p "$pid"
done
[/tmp]$
Vino