V
V
Vadim Ushakov2021-08-02 19:33:23
linux
Vadim Ushakov, 2021-08-02 19:33:23

Is it possible to force a change to a running object in the filesystem?

The question is, is it possible with a simple method to change the file of a running process from within the process itself?

When using ofstream, I get this output.


Got an error opening self: `Text file busy`


Tried the code
int fd;
  fd = open (GlobalFilesystemPathToRunningObject.c_str(), O_RDONLY);
  std::cout << fd << std::endl;
  std::cout << flock(fd, LOCK_UN) << std::endl;
  std::cout << open (GlobalFilesystemPathToRunningObject.c_str(), O_RDWR) << std::endl;

  std::ofstream file(GlobalFilesystemPathToRunningObject.c_str(), std::ios_base::app);
  if (file.fail())
        std::cout << "Got an error openning self: `" << std::strerror(errno) << "`" << std::endl;
  {
    file << data.c_str();
    file.close();
  }


To no avail.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question