>> Delete Reply from No. 0 article
No. RE: RE: 소스를 어떻게 변경할수는 없을까요?

등록 2001-04-17 10:10:00 By localhost     조회 2
이름 차주현    

		#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