uid, guid 검색
- uid 검색
#include<sys/types.h
#include<unistd.h
uid_t getuid(void);
uid_t geteuid(void);
- guid 검색
#include<sys/types.h
#include<unistd.h
gid_t getgid(void);
gid_t getegid(void);
directory tree
- 사용법
#include <ftw.h>
int ftw(const char *path, int(*func)(), int depth);
//첫번째 인자 : 어디부터 시작할지. 시작할 디렉토리 이름
//두번째 인자 : 어떤 작업을 할 것인지 (function 이름)
// 반복적으로 실행함
- path에서 시작해서 recursive하게 subdirectory와 file들에 func() 함 수를 적용
- depth : ftw에 의해 사용 가능한 file descriptor의 수
- 사용법 :
int func (const char *name, const struct stat *sptr, int type){ }
//무조건 반환값은 int형 이어야 함
//name : 누구에 대해 작업하고 있는지 파일 이름 또는 디렉토리 이름(os가 알려줌)
//os가 stat 명령 적용시킴
//type : 어떤 타입인지
- name : target object의 이름
- sptr : object에 대한 자료가 저장된 stat에 대한 pointer
- type :
FTW_F object가 file
FTW_D object가 directory
FTW_DNR object는 읽을 수 없는 directory
FTW_NS object는 ? //stat 적용이 불가한 object (null값)
- 함수가 0이 아닌 return값을 가지거나, error 발생하면 중단
#include <sys/stat.h>
#include<ftw.h>
int list(const char *name, const struct stat *status, int type) {
if (type==FTW_NS)
return 0;
if (type==FTW_F)
printf("%-30s\t0%3o\n", name, status->st_mode&0777);
else
printf("%-30s*\t0%3o\n", name, status->st_mode&0777);
return 0;
}
int main(){
ftw(".", list, 1); //current working directory부터 시작
return 0;
}
'전공 > 유닉스' 카테고리의 다른 글
6장. 프로세스 생성과 실행 (1) | 2023.11.01 |
---|---|
5장. 프로세스 정보 (0) | 2023.11.01 |
3장. 파일과 디렉토리 (1) | 2023.11.01 |
2장. 파일 입출력 (2) (1) | 2023.10.23 |
2장. 파일 입출력 (1) (1) | 2023.10.05 |
댓글