Truncating a file while it's being used (Linux)

后端 未结 13 2172
名媛妹妹
名媛妹妹 2020-12-05 01:54

I have a process that\'s writing a lot of data to stdout, which I\'m redirecting to a log file. I\'d like to limit the size of the file by occasionally copying the current

13条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-05 02:35

    Did you check the behavior of any signals like SIGHUP to the third party product, to see if it will start logging a fresh file? You would move the old file to a permanent name, first.

    kill -HUP [process-id]

    And then it would start writing out again.

    Alternatively (as Billy suggested) maybe redirecting the output from the application to a logging program like multilog or the one that is commonly used with Apache, known as cronolog. Then you'll have more fine grained control of where everything goes before it is written to that initial file descriptor (file), which is really all it is.

提交回复
热议问题