Ben kullanımını anlamaya çalışıyorum dup2ve dup.
Man sayfasından:
DESCRIPTION
dup and dup2 create a copy of the file descriptor oldfd.
After successful return of dup or dup2, the old and new descriptors may
be used interchangeably. They share locks, file position pointers and
flags; for example, if the file position is modified by using lseek on
one of the descriptors, the position is also changed for the other.
The two descriptors do not share the close-on-exec flag, however.
dup uses the lowest-numbered unused descriptor for the new descriptor.
dup2 makes newfd be the copy of oldfd, closing newfd first if necessary.
RETURN VALUE
dup and dup2 return the new descriptor, or -1 if an error occurred
(in which case, errno is set appropriately).
Bu sistem çağrısına neden ihtiyacım olsun? dosya tanımlayıcısını çoğaltmanın faydası nedir?
Dosya tanımlayıcım varsa, neden bir kopyasını almak isteyeyim?
Nerede dup2/ dupgerekli olduğu konusunda bana bir örnek verebilirseniz çok sevinirim .
Teşekkürler
dupveya olmadan nasıl uygularsınızdup2? Aramanızpipe(2)ve ardından dosya tanımlayıcılardan birine sahip olmanız gerekirdupSTDIN_FILENO