Article Listing 1 Listing 2 Listing 3 Listing 4
Listing 5 Listing 6 Listing 7 Listing 8 Listing 9
Listing 10 Listing 11 Listing 12 Listing 13 Sidebar aug2004.tar

Listing 8 get_num_resources()

{
    # Echos the number of resources that a semaphore has. (See also
    # Init_semaphore).  Return the contents of the specified semaphore's
    # resource file, and return 0 if the semaphore has been initialized;

    local FUNC_NAME=get_num_resources
    ${TRACE:-trace $FUNC_NAME $@}

    local semaphore=$1
    local resources_file=$HOME_DIR/$semaphore/$RESOURCES_FILENAME

    assert_semaphore $semaphore

    integer num_resources=$(cat -s $resources_file)
    echo ${num_resources:-0}
}