>> Edit article
이름
제목
패스워드
#include <stdio.h> #include <sys/types.h> #include <fcntl.h> int main() { int fd, a; pid_t pid; char file[512]; char buf[10]; pid = getpid(); sprintf(file, "wtest.%d", pid); sprintf(buf, "%d", pid); fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0644); printf("pid is %d ", pid); write(fd, buf, sizeof(pid)); close(fd); return 0; } 시스템콜이 안되면 perror 로 확인하세요. : : 사람들의 생각은 다들 비슷하다고나 해야하나? 암튼.. : : : : root 로 login 한 다음 man pidof 라고 입력해 보시기 바랍니다. : : : : /etc/rc.d/init.d 디렉토리 밑의 파일들을 참고해도 사용법을 대략 : : 알수 있습니다. : : : : : 유닉스 상에서 getpid() 함수를 써서 현재 프로세스의 id 를 : : : 파일에 쓰고 파일을 저장 하고 : : : 싶습니다.. : : : 제가 간단하게 구현을 해보았는데.. : : : 파일이 만들어지기는 하는데 파일안에 내용이 써지질 않는군요.. : : : 그냥 0 byte 의 파일이 생기네요... : : : 어떻게 해야 할지요? : : : 고수님들의 한수 부탁합니다.. : : : 소스는 다음과 같습니다.. : : : : : : ------------------------------------------- : : : : : : #include <stdio.h> : : : #include <unistd.h> : : : #include <fcntl.h> : : : : : : int main() : : : { : : : int fd; : : : pid_t pid; : : : char file[512]; : : : int filedes; : : : pid = getpid(); : : : : : : sprintf(file, "wtest.%d", pid); : : : : : : fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0644); : : : : : : printf("pid is %d ", pid); : : : : : : write(fd, (char *)pid, 8); : : : close(fd); : : : return 0; : : : } -- return true
Copyleft
1999-2026 by
JSBoard Open Project
Theme Designed by
IDOO
All right reserved