Linux系统调用 access函数详解
Linux系统调用--access函数详解
2007-07-30 23:10
【access系统调用】
功能描述:
检查调用进程是否可以对指定的文件执行某种操作。
用法:
#include <unistd.h>
#include <fcntl.h>
int access(const char *pathname, int mode);
参数:
pathname: 需要测试的文件路径名。
mode: 需要测试的操作模式,可能值是一个或多个R_OK(可读?), W_OK(可写?), X_OK(可执行?) 或 F_OK(文件存在?)组合体。
返回说明:
成功执行时,返回0。失败返回-1,errno被设为以下的某个值
EINVAL: 模式值无效
EACCES: 文件或路径名中包含的目录不可访问
ELOOP : 解释路径名过程中存在太多的符号连接
ENAMETOOLONG:路径名太长
ENOENT: 路径名中的目录不存在或是无效的符号连接
ENOTDIR: 路径名中当作目录的组件并非目录
EROFS: 文件系统只读
EFAULT: 路径名指向可访问的空间外
EIO: 输入输出错误
ENOMEM: 不能获取足够的内核内存
ETXTBSY:对程序写入出错
例子:
/* test.c */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("Usage: ./test filename\n");
exit(1);
}
if (access(argv[1], F_OK) == -1) {
puts("File not exists!");
exit(2);
}
if (access(argv[1], R_OK) == -1)
puts("You can't read the file!");
else
if (access(argv[1], R_OK | W_OK) != -1)
puts("You can read and write the file");
else
&n
相关文档:
Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......
软件环境
debian 5.0
Apache Httpd 2.0.63 (http://httpd.apache.org
)
OpenSSL 0.9.81 (http://www.openssl.org/source
)
SSL-Tools (http://www.openssl.org/contrib/ssl.ca-0.1.tar.gz
)
安装步骤(所有操作使用root用户进行):
1. OpenSSL
#tar zxvf openssl-0.9.81.tar.gz
#cd openssl-0.9.81
#./config
# ......
http://blog.csdn.net/compiler_hdz/archive/2006/01/10/575113.aspx
先看一个“hello world!”的例子:
在某个目录下新建一个文件,叫hello.sh,敲入以下代码:
#!/bin/sh
echo "hello world!"
好,就这些。保存,在命令提示符下进入保存“hello.sh”的目录,这样执行:
......
在linux下面安装mysql,首相要根据操作系统的版本,选择对应的mysql的版本,官方网站上有非常明确的分类
http://dev.mysql.com/downloads/
在这里我实验的操作系统是redhat linux
mysql 用了两个安装包,一个是server端,一个是client,我用的是rpm包,安装的指令比较简单。
MySQL-server-community-5.1.42-0.rhel4.i38 ......
相关函数
fork,execve,waitpid,popen
表头文件
#i nclude<stdlib.h>
定义函数
int system(const char * string);
函数说明
system()会调用fork()产生子进程,由子进程来调用/bin/sh-c string来执行参数string字符串所代表的命令,此命>令执行完后随即返回原调用的进程。在调用system()期间SIGCHLD 信 ......