What does lock keyword in open function?

Since you’re looking for write-exclusivity, you need to use a lockfile here. The basic idea is described briefly in this SO answer (the couple paragraphs after ‘The main reason why this flag exists are “lock files”’).

First, we should decide on a location for the lockfile. This should be some constant location that both your processes know about, and somewhere you have write permission. On Linux Mint, you should be able to create and use a folder under XDG_RUNTIME_DIR:

# either in global scope or inside a `main` function if you have one
const lockfile_location = joinpath(ENV["XDG_RUNTIME_DIR"], "ritulahkar")
mkpath(lockfile_location)
"/run/user/1000/ritulahkar"

This should be done near the start of your program (mkpath doesn’t error if the folder already exists, so it’s ok to do this from both processes).

Wherever either of your processes wants to write to the shared file, it should first check for the lock file. It should only write to the main shared file if the lock file doesn’t already exist, and in that case it should create the lock file to notify that it’s currently writing to the shared file.

using FileWatching: watch_file
using Base.Filesystem

function write_to_shared_file(sharedfilename, contenttowrite)
  lockacquired = false
  lockfilename = lockfile_location * basename(sharefilename) * ".lock"
  local lockfilehandle 
  while !lockacquired
    while isfile(lockfilename)
      # watch_file will notify if the file status changes, waiting until then
      # here we want to wait for the file to get deleted
      watch_file(lockfilename)
    end
    try
      # try to acquire the lock by creating lock file with JL_O_EXCL (exclusive)
      lockfilehandle = Filesystem.open(lockfilename, JL_O_CREAT | JL_O_EXCL, 0o600)
      lockacquired = true
    catch err
      # in case the file was created between our `isfile` check above and the
      # `Filesystem.open` call, we'll get an IOError with error code `UV_EEXIST`.
      # In that case, we loop and try again. 
      if err isa IOError && err.code == Base.UV_EEXIST
        continue
      else
        rethrow()
      end
    end
  end
  # now that the lock is acquired, we can safely write to
  # the actual shared file we want to write to
  open(sharedfilename, append = true) do sharedfile
     # write to the sharedfile here just as usual
     write(sharedfile, contenttowrite)
  end

  # free up the lock so that the other process can acquire it if it needs
  close(lockfilehandle)
  Filesystem.unlink(lockfilename)
end

This function should exist in both the processes, and whenever either process wants to write to the shared file, it should go through this function.