Cache pid to avoid multiple reads; also add some error handling.

Caution:
-------
The cached pid value will not be updated if "enable_trace_logs" file
is overwritten with a new pid. In order to trace a new process,
explicitly remove and create a new enable_trace_logs file with the
respective pid.