[BASH] xclock/xcalc/xterm...process question?

I have no idea how to do this:

Let's say the user opens an "xclock &" in one of my scripts and I don't want him to be able to re-open one with the script. How could I test that? Possibly with a message saying that "The <xclock(or w/e other process like xcalc)> is already running in the background".

I checked the ps command but I can't figure out what I could do with it.

Thanks in advance.

This will get you started:

progname="xclock"
username=`id|cut -d\( -f2|cut -d\) -f1`
running=`ps -fu $username|grep "$progname"|grep -v grep`
if [ ! -z "${running}" ] ; then
    echo "$progname already running [$running]"
else
    $progname &
fi

I see that progname would contain something related to xclock. Does that mean I'd have to rinse-repeat for each other application I'd like to block?

You can change this:

progname="xclock"

To:

progname="$1"

And then use the script I provided as kind of a generic launcher which will take program name as input. There are multiple ways of ensuring that only one instance runs for a user like checking ps or creating lockfiles etc.etc. Modify suitably to best suit your environment / requirements. I assume you will be able to figure that out by yourself.