SCP 是否锁定正在传输的文件?

SCP 是否锁定正在传输的文件?

假设我们的应用程序日志位于 AIX 服务器上。应用程序不断向日志中写入数据,而 Windows 上的用户想要查看该文件。他们一直在使用 WinSCP 将文件传输到桌面,然后使用文本编辑器打开它。

我认为可能发生的情况是 scp 在传输期间锁定文件,并且应用程序不再能够写入文件。我认为这是因为日志文件将在一天中的随机时间点停止增长。

那可能是正在发生的事情吗?

答案1

你为什么不试试这个呢?开始 scp 一个大文件,然后lsof /path/to/file在 AIX 服务器上运行,看看 FD 列显示什么。

来自 lsof 手册页:

   FD         is the File Descriptor number of the file or:
                   cwd  current working directory;
                   Lnn  library references (AIX);
                   err  FD information error (see NAME column);
                   jld  jail directory (FreeBSD);
                   ltx  shared library text (code and data);
                   Mxx  hex memory-mapped type number xx.
                   m86  DOS Merge mapped file;
                   mem  memory-mapped file;
                   mmap memory-mapped device;
                   pd   parent directory;
                   rtd  root directory;
                   tr   kernel trace file (OpenBSD);
                   txt  program text (code and data);
                   v86  VP/ix mapped file;
              FD is followed by one of these characters, describing the mode under which the file is open:
                   r for read access;
                   w for write access;
                   u for read and write access;
                   space if mode unknown and no lock
                        character follows;
                   `-' if mode unknown and lock
                        character follows.
              The mode character is followed by one of these lock characters, describing the type of lock applied to the file:
                   N for a Solaris NFS lock of unknown type;
                   r for read lock on part of the file;
                   R for a read lock on the entire file;
                   w for a write lock on part of the file;
                   W for a write lock on the entire file;
                   u for a read and write lock of any length;
                   U for a lock of unknown type;
                   x for an SCO OpenServer Xenix lock on part of the file;
                   X for an SCO OpenServer Xenix lock on the entire file;
                   space if there is no lock.
              See the LOCKS section for more information on the lock information character.
              The FD column contents constitutes a single field for parsing in post-processing scripts.

如果你这样做,至少在 Linux 上,你会看到 FD 列是“3r”,这意味着它具有某种读锁,但我不确定它前面的 3 是什么意思。

答案2

大多数 Unix 程序不使用锁定或者当他们使用它时,它不是强制性的,所以我怀疑锁定是否会阻止日志增长。更可能是 SCP 传输减慢了日志写入速度。

相关内容