C언어와 유닉스 프로그램 언어가 같기에 질문을 드려봅니다.
의사양반
질문 제목 :C언어와 유닉스 프로그램 언어가 같기에 질문을 드려봅니다.
질문 요약 :3개의 프로그램을 하나로 합치고 싶어요질문 내용 :
말그대로 세개의 프로그램을 하나로 합치고 싶습니다. 소스는 있습니다. 합쳐서 하나로 만들어 주세요 ㅠ.ㅠ
쪽지로 보내주셔도 좋고 메일도 좋습니다. 그리고 합칠때 어떻게 합쳤는지도 알려주셨으면 좋겠습니다. ㅠ.ㅠ
1. fifo를 사용해 1:1대화가 가능하게
2. 타이머 설정을 해서 타임이 다되면 1/1대화가 종료 되게
3. 1/1프로그램의 프로세스 실행 시간 측정
이렇게 3가지 입니다.
제가 가지고 있는 소스는 1번 1/1대화는 완변하게 구현되었습니다. 2번은 그냥 타이머 설정 입니다. 3번은 단순히 times 함수를 이용해서 실행시간측정하는 소스입니다.
이 세가지를 연결 할수 있나요??? ㅠ.ㅠ
연결 하면 이렇게 구성이 되겠죠 1:1대화중에 타이머가 시간이 다되면 프로그램이 종료되고 해당 프로그램의 실행 시간을 측정도와주세요 ㅠ.ㅠ1번 대화가 가능하게 하는 소스 입니다.서버 소스
#include sys/types.h
#include sys/stat.h
#include fcntl.h
#include stdio.h
#include stdlib.h
#include unistd.h
main() {
int pd, pd1, n;
char msg[256];
if(mkfifo(./myfifo, 0666) == -1) {
perror(mkfifo);
exit(1);
}
if(mkfifo(./myfifo1, 0666) == -1) {
perror(mkfifo);
exit(1);
}
pd = open(./myfifo, O_WRONLY);
pd1 = open(./myfifo1, O_RDONLY);
if(pd == -1) {
perror(open);
exit(1);
}
while(1) {
printf(Server : );
gets(msg);
n = write(pd, msg, strlen(msg)+1);
if(n == -1) {
perror(write);
exit(1);
}
n = read(pd1, msg, 255);
printf(Client : %s\n, msg);
}
}
클라이언트 소스
#include sys/types.h
#include sys/stat.h
#include fcntl.h
돋움체#include stdio.h
#include stdlib.h
#include unistd.h
main() {
int pd, pd1, n;
char inmsg[256];
pd = open(./myfifo, O_RDONLY);
pd1 = open(./myfifo1, O_WRONLY);
if(pd == -1) {
perror(open);
exit(1);
}
printf(Client =====\n);
while(1) {
n=read(pd, inmsg, 255);
printf(Server : %s\n, inmsg);
printf(Client : );
gets(inmsg);
write(pd1, inmsg, strlen(inmsg)+1);
}
}
2번 타이머 설정 소스 입니다.
#include sys/time.h
#include unistd.h
#include signal.h
#include stdlib.h
#include stdio.h
void handler() {
printf(Timer Invoked..\n);
}
int main(void) {
struct itimerval it;
sigset(SIGALRM, handler);
it.it_value.tv_sec = 3;
it.it_value.tv_usec = 0;
it.it_interval.tv_sec = 2;
it.it_interval.tv_usec = 0;
if (setitimer(ITIMER_REAL, &it, (struct itimerval *)NULL) == -1) {
 sp; perror(setitimer);
exit(1);
}
while (1) {
if (getitimer(ITIMER_REAL, &it) == -1) {
perror(getitimer);
exit(1);
}
printf(%d sec, %d msec.\n, (int)it.it_value.tv_sec,
(int)it.it_value.tv_usec);
sleep(1);
}
return 0;
}
3. 1:1프로그램의 프로세스 실행 시간 측정 소스#include sys/types.h
#include sys/times.h
#include limits.h
#include unistd.h
#include stdlib.h
#include stdio.h
int main(void) {
int i;
time_t t;
struct tms mytms;
clock_t t1, t2;
if ((t1 = times(&mytms)) == -1) {
perror(times 1);
exit(1);
}
for (i = 0; i 999999; i++)
time(&t);
if ((t2 = times(&mytms)) == -1) {
perror(times 2);
exit(1);
}
printf(Real time : %.1f sec\n, (double)(t2 - t1) / CLK_TCK);
printf(User time : %.1f sec\n, (double)mytms.tms_utime / CLK_TCK);
printf(System time : %.1f sec\n, (double)mytms.tms_stime / CLK_TCK);
return 0;
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2690777 | 말 표현에서 궁금한점이 있습니다. 배열을 통째로 넘겨받으려면 매개변수로 배열을 선언할 수 있어야한다? (8) | 별햇님 | 2025-04-07 |
2690749 | 피라미드 질문드립니다 (for문 한개) | 도래솔 | 2025-04-07 |
2690718 | 함수 포인터반환 함수 질문 | 에드워드 | 2025-04-07 |
2690685 | 2중for문 도와주세여..;; | 흰추위 | 2025-04-07 |
2690655 | 팩토리얼 계산문제..질문~ (9) | 옆집꼬마야 | 2025-04-06 |
2690627 | c 변수 선언후 변수값 저장안하고 출력 | 방방 | 2025-04-06 |
2690600 | 릴리즈 모드로 컴파일해서 다른 컴퓨터에서도 실행파일을 실행할수 있는 방법 알려주세요 (5) | 제나 | 2025-04-06 |
2690576 | bin파일 저장 | 다올 | 2025-04-06 |
2690547 | C언어 뒷부분이라 너무 어려워서요;; 프로그래밍 하나만 부탁드립니다 (4) | 그루터기 | 2025-04-05 |
2690517 | cygwin에서요.. (1) | 엘보어 | 2025-04-05 |
2690486 | 문자열과 문자형이요 ~ | 다스리 | 2025-04-05 |
2690344 | 일본어 주석 깨짐 문제 (3) | 연하얀 | 2025-04-04 |
2690314 | 암호문 만들기 -비제네르- | 이퓨리한나 | 2025-04-03 |
2690292 | 왕초보자의 질문!!!!!! 도와주세요 (1) | 하랑 | 2025-04-03 |
2690269 | 정올 문제 인데.. 흠 | 반월 | 2025-04-03 |
2690237 | sizeof에서 short형을 썻는데 왜 4byte가 나올까요? (1) | 바나나 | 2025-04-03 |
2690183 | 문자열과 포인트 비교 (2) | 미즈 | 2025-04-02 |
2690154 | a -48 ? | 희미한눈물 | 2025-04-02 |
2690094 | 테트리스 질문요. | 지후 | 2025-04-01 |
2690066 | 문자열비교!! (1) | 매디 | 2025-04-01 |