#include <unistd.h>
int unlink(const char *pathname):
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
int main()
{
int file_desc;
file_desc = open("/tmp/LCK.unlink.test", O_RDWR | O_CREAT | O_EXCL, 0444);
if (file_desc == -1) {
printf(" File already exist !\n");
exit(EXIT_SUCCESS);
} else {
printf(" Open succeeded..now for 5s and unlink it and open again\n");
sleep(5);
unlink("/tmp/LCK.unlink.test");
printf(" unlink have done....,open again..\n");
file_desc = open("/tmp/LCK.unlink.test", O_RDWR | O_CREAT | O_EXCL, 0444);
if (file_desc == -1) {
printf(" unlink failure \n");
exit(EXIT_SUCCESS);
} else {
printf("unlink succeeded\n");
exit(EXIT_SUCCESS);
}
}
exit(EXIT_SUCCESS);
}
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main (void)
{
char buf [128];
int fd;
int sndfd;
int n;
if ((fd = open ("test.txt", O_RDONLY)) == -1) {
perror("open");
exit(1);
}
buf [0] = (char)fd;
mkfifo ("send_fifo", 0777);
sndfd = open ("send_fifo", O_WRONLY);
write (sndfd, buf, 1);
unlink ("test.txt");
n = read (fd, buf, 128);
buf [n] = '\\0';
printf ("%s\\n", buf);
close (fd);
unlink ("send_fifo");
return (0);
}
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
int main (void)
{
int fd;
char buf [10];
char buffer [128] = "hello world";
int revfd;
if ((fd = open ("test.txt", O_WRONLY)) == -1) {
perror("write");
exit(1);
}
revfd = open ("send_fifo", O_RDONLY);
read (revfd, buf, 1); /*得到客户机对test.txt的文件描述符*/
write ((int)buf[0], buffer, 128);
close (fd);
return 0;
}
欢迎光临 曲径通幽论坛 (http://www.groad.net/bbs/) | Powered by Discuz! X3.2 |