Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Linux Ask!

Mar 022010
 

How to check if a file is locked in Linux?

Answer:

Suppose a file test.txt is being locked by a program, e.g. using the flock system call, how can we know if this file is really being locked?

# lsof test.txt
COMMAND  PID USER   FD   TYPE DEVICE SIZE   NODE NAME
perl    5654 john 3uW  REG    8,1    1 983057 test.txt

The W means the file is currently held by an exclusive lock. You can find more information in the link below:

http://linux.die.net/man/2/flock

Mar 012010
 

How to perform syntax check for Python program

Answer:

Assume you have a simple Python script hello.py, you want to perform syntax check. You can use the following method

# python -c 'import hello'

Traceback (most recent call last):
  File "", line 1, in 
  File "hello.py", line 1
    echo "Hello, World!"

If there is any syntax error, it will prompt out to the screen.