Compile it for me. -- Linux general technology-Linux programming and kernel information. The following is a detailed description. The source code of my program is as follows:
# Include
# Include
# Include
# Include
Int main (int argc, char * argv [])
{
Int fd;
Struct flock fl;
Fd = open ("testfile", O_RDWR );
If (fd =? 1)
/* Handle error */;
/* Make a non-blocking request to place a write lock on bytes 100? 109 of testfile */
{
Fl. l_type = F_WRLCK;
Fl. l_whence = SEEK_SET;
Fl. l_start = 100;
Fl. l_len = 10;
}
If (fcntl (fd, F_SETLK, & fl) =? 1)
{
If (errno = EACCES | errno = EAGAIN ){
Printf ("Already locked by another process \ n ");
/* We can't get the lock at the moment */
} Else {
/* Handle unexpected error */;
}
} Else {/* Lock was granted ...*/
/* Perform I/O on bytes 100 to 109 of file */
/* Unlock the locked bytes */
Fl. l_type = F_UNLCK;
Fl. l_whence = SEEK_SET;
Fl. l_start = 100;
Fl. l_len = 10;
If (fcntl (fd, F_SETLK, & fl) =? 1)
/* Handle error */;
}
Exit (EXIT_SUCCESS );
}
I don't know why I didn't compile it on my machine.
My GCC version is as follows:
Cwqing1973 @ cwqing1973-desktop :~ $ Gcc-v
Use built-in specs.
Goals: x86_64-linux-gnu
Configuration :.. /src/configure-v -- enable-languages ages = c, c ++, fortran, objc, obj-c ++, treelang -- prefix =/usr -- enable-shared -- with-system-zlib -- libexecdir =/usr/lib -- without-included-gettext -- enable-threads = posix -- enable-nls -- with-gxx-include-dir =/usr/include/c ++/4.2 -- program-suffix =-4.2 -- enable-clocale = gnu -- enable-libstdcxx-debug -- enable- objc-gc -- enable-mpfr -- enable-checking = release -- build = x86_64-linux-gnu -- host = x86_64-linux-gnu -- target = x86_64-linux-gnu
Thread model: posix
Gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)
Cwqing1973 @ cwqing1973-desktop :~ $
Thank you.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.