<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def pid_lock(path):
 """ Write the file in a file on the system. Check if the process is not already running. """


    if os.path.exists(path):
        pid = None
        try:
            with open(path) as f:
                try:
                    pid = int(f.read())
                    os.kill(pid, 0)  # kill returns an error if the process is not running
                except (OSError, SystemError, ValueError):
                    pid = None
        except OSError as e:
            log.critical("Can't open pid file %s: %s", pid, str(e))
            sys.exit(1)

        if pid:
            log.critical("GNS3 is already running pid: %d", pid)
            sys.exit(1)

    try:
        with open(path, 'w+') as f:
            f.write(str(os.getpid()))
    except OSError as e:
        log.critical("Can't write pid file %s: %s", path, str(e))
        sys.exit(1)