head 로 보면 정상인데 VI 로 열어 보면 이상이 있어 보이는 경우

swish95의 이미지

head 로 보면 정상적으로 보입니다.

2024-04-02 23:59:16.756  INFO 6624 --- [   scheduling-1] c.m.f.c.HttpClientConfiguration          : Run idleConnectionMonitor, pool counts=0
2024-04-03 00:00:56.757  INFO 6624 --- [   scheduling-1] c.m.f.c.HttpClientConfiguration          : Run idleConnectionMonitor, pool counts=0
2024-04-03 00:02:36.757  INFO 6624 --- [   scheduling-1] c.m.f.c.HttpClientConfiguration          : Run idleConnectionMonitor, pool counts=0
2024-04-03 00:04:16.757  INFO 6624 --- [   scheduling-1] c.m.f.c.HttpClientConfiguration          : Run idleConnectionMonitor, pool counts=0
2024-04-03 00:05:56.758  INFO 6624 --- [   scheduling-1] c.m.f.c.HttpClientConfiguration          : Run idleConnectionMonitor, pool counts=0

그런데 이 파일을 vi 로 열어보면 이런식으로 보입니다.

^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^

첫번째 줄만 그렇고 두번째 줄 부터는 정상입니다.

head 에 보인 첫줄이 저렇게 표시되는것 같은데... 크게 상관은 없는데 신기 하네요

혹시 아는 분이 있을까요?

ps. crontab 에서 해당 파일을 cat /dev/null > a.log 이런식으로 해주긴 했습니다.

ymir의 이미지

^@ 는 null 문자 입니다.
head 로 보면 어차피 printable ascii 만 보이니까, null 이 있는지 알 수 없지만..
vi 로 열어 보면, null 문자를 그렇게 표시해 주니까 알게 되는 거죠.
file 명령으로 확인해 보면, ascii text 가 아니라 binary data 로 표시될 것 같네요.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

swish95의 이미지

하나면 들어가면 모를까 이렇게 많이 들어가다니.. 뭐낙 제가 모르는 동작이 숨어 있지는 않을까요?

------------------------------------------------------------
ProgrammingHolic

ymir의 이미지

cat /dev/null 을 이용해서 파일 크기를 0 으로 줄였다 하더라도, 로그를 생성하는 프로그램이 O_APPEND 없이 파일을 열었다면, 실제 파일의 끝이 아닌 현재 fd 의 offset 에 파일을 쓰려고 하기 때문에, 앞 부분이 모두 null byte 로 채워질 겁니다.
이런 경우라면, 로그 파일을 초기화 하실 때 프로세스도 같이 재시작 해주셔야 할 것 같네요.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

swish95의 이미지

100% 이해 했습니다.

------------------------------------------------------------
ProgrammingHolic

swish95의 이미지

해당 프로세스 실행시에

]$ myProcess > mylog.log 2>&1 & 

이렇게 실행하니 말씀하신 offset 문제가 생겼던 거네요
]$ myProcess >> mylog.log 2>&1 & 

이렇게 append 모드로 하니 문제는 해결되었습니다.

물론 log 찍을때 append 하는 동작 - 파일의 끝을 다시 찾는? - 이 조금 느려지긴 했을수도 있겟네요

------------------------------------------------------------
ProgrammingHolic

ymir의 이미지

실제 커널에서 write 를 어떻게 처리하는 지는 잘 모르겠지만..
어차피 fd 에 연결된 inode 가 있고, 거기에 file size 관련된 정보도 있을 테니..
write 하기 전에 offset 바꾸는 건 일도 아닐 겁니다.
그게 append mode 가 아닌 경우에 비해, 유의미한 성능 차이가 있을 거라고 생각하기는 좀 어렵지 않나 싶네요.

되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』

swish95의 이미지

보름쯤 지나고 보니 로그가 계속 자라고 있더라구요

덕분에 깔끔하게 해결되었습니다.

저도 모르게 아는척 하고 싶었던건지도 모르겠습니다.

답해주신 글보니 저는 아직 멀었네요 ^^

------------------------------------------------------------
ProgrammingHolic

dontdieych의 이미지

ps. crontab 에서 해당 파일을 cat /dev/null > a.log 이런식으로 해주긴 했습니다.

저 명령어는 a.log 파일을 지우는 (이미 있는 내용도 다 지워 버리는) 일을 합니다.

head 명령어로 보신 파일과 vi로 보신 파일이 정말로 같은 파일 인지 의심되네요.

swish95의 이미지

네 파일은 같은거였고 ymlr 님 답으로 이해 한것 같습니다.

------------------------------------------------------------
ProgrammingHolic

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.