Check whether the flag file is running or not.
Process detection that can be added with related keywords.
Code(Simple CSH instance) running_check
# ! /Bin/CSH-F
If ($ # Argv <2) then
Usage:
Echo " Usage: $0 <running_flag> <action> <timeout> "
Echo " Action need be one value of-check or-Delete. "
Echo " Default timeout is 0, it means no timeout limitation. "
Exit 1
Endif
Set running_flag = $ 1
Set action = $2
Set timeout = 0
If ( " $3 " ! = "" ) Set timeout = $ 3
If ( " $ Action " ! = " -Check " && " $ Action " ! = " -Delete " ) Goto Usage
# Wait until the flag is deleted by ohter processes or timeout.
Set waittime =0
If ( " $ Action " = " -Check " &-E $ Running_flag ) Then
Echo " Running flag is existed, please wait! "
Set running = 1
Set sleeptime = 60
While (( " $ Timeout " ! = " 0 " && $ Waittime < $ Timeout )&&$ Running \
| " $ Timeout " = " 0 " && $ Running )
Echo " Sleep $ sleeptime " &&Sleep $ Sleeptime
@ Waittime + = $ Sleeptime
If (! -E $ Running_flag ) Set running = 0
End
Endif
# Timeout, delete the flag.
If (" $ Timeout " ! = " 0 " && " $ Waittime " > = " $ Timeout " ) Then
Echo " Timeout $ timeout "
Echo " Delete running flag "
If (-E $ Running_flag ) Rm $ Running_flag
Endif
# If check, set new flag.
# If Delete, delete the flag.
If ( " $ Action " = " -Check " ) Then
Echo " Touch running flag "
Touch $ Running_flag
Echo 'date'> $ Running_flag
Ls-l $ Running_flag
Else
Echo " Delete running flag "
If (-E $ Running_flag ) Rm $ Running_flag
Endif
Exit 0
Complete!