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;
}
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700530 | 전처리문 질문입니다. (1) | 아놀드 | 2025-07-05 |
2700510 | c언어를 어케하면 잘할수 있을까요.. | 연연두 | 2025-07-05 |
2700484 | 두 개가 차이가 뭔지 알려주세요...(소수 찾는 프로그램) (2) | 날위해 | 2025-07-05 |
2700426 | 인터넷 창 띄우는 질문이요 (1) | 정훈 | 2025-07-04 |
2700400 | 원넓이를 계산이요 ㅜㅜ | 천칭자리 | 2025-07-04 |
2700368 | if에 관해서 질문이요... | Orange | 2025-07-04 |
2700339 | 이거 결과값이 왜이런건지.. (4) | 그댸와나 | 2025-07-04 |
2700313 | 파일 읽어서 저장하는데 빈파일일 경우 문재가 발생하네요.. (2) | 크나 | 2025-07-03 |
2700287 | 구조체 동적할당 연습을 하는데 오류가 뜹니다...(해결) (3) | 아련나래 | 2025-07-03 |
2700264 | 문자와 숫자 동시에 입력??? | 글고운 | 2025-07-03 |
2700236 | txt파일로만 쓰고 읽게 하려면 어떻게 해야 하나요..?? (8) | 미국녀 | 2025-07-03 |
2700211 | 전위 연산자 (2) | 어른처럼 | 2025-07-02 |
2700183 | C에서 파일이름을 받고, 그 파일의 사이즈를 출력해줘야하는데 내용이 출력이 안되네요 ;ㅅ; | 피스케스 | 2025-07-02 |
2700150 | 꼭좀 도와주세요ㅠㅠㅠ | 호습다 | 2025-07-02 |
2700095 | 연산문제...질문... | 오빤테앵겨 | 2025-07-01 |
2700070 | while문 , 3의배수 출력하는 프로그램좀 짜주세욤. | 횃불 | 2025-07-01 |
2700041 | 초보인데요 ㅎ 배열안에 배열을 집어넣을수 있나요?? | 헛장사 | 2025-07-01 |
2700012 | 배열// (1) | 전갈자리 | 2025-07-01 |
2699895 | 무한루프에 빠집니다.!! 해결좀부탁드려요 (10) | 선아 | 2025-06-30 |
2699842 | 질문을 너무 많이 하네여.....죄송.... (2) | 해님꽃 | 2025-06-29 |