system 함수가 명령을 두번 실행시키는 경우도 있나요?
글쓴이: trymp / 작성시간: 목, 2014/03/13 - 10:35오후
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
void* func1(void* arg)
{
int num = 1;
int status;
char cmd[100];
while (1)
{
num %= 5;
if (num <=0 )
num++;
snprintf(cmd, sizeof(cmd), "dd if=/dev/zero of=/aa.dump bs=%dk count=10000 &> /dev/null", num);
status = system(cmd);
printf("status A %d (%d) \n", num++, status);
}
printf("AAAAA \n");
return;
}
int main(int ac, char *av[])
{
pthread_t th[3];
pthread_create(&th[0], NULL, &func1, (void *)NULL);
pthread_join(th[0], NULL);
return 0;
}위의 코드의 결과가
8192 pts/0 S+ 0:00 sh -c dd if=/dev/zero of=/aa.dump bs=2k count=10000 &> /dev/null
8193 pts/0 R+ 0:00 sh -c dd if=/dev/zero of=/aa.dump bs=2k count=10000 &> /dev/null
이렇게 두개 실행될수도 있나요?
system() 함수는 command 가 완전히 종료된 다음 리턴되지 않나요?
이해가 되지 않는 경우라 고수들의 조언 부탁드립니다
Forums:


댓글 달기