아래 쉘 프로그램으로 바꾸려는 토크 나이저가 있습니다. 나는이 프로그램이 모든 쉘 명령을 사용하도록 설정되어 있지는 않지만 현재 작업중인 디렉토리를 인쇄하는 데 문제가 있음을 알기에 막 시작했습니다. 나는 아래에있는 내 코드가 표시됩니다 :현재 작업 디렉토리 인쇄하기
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
int main()
{
pid_t pid;
char cwd[1000];
if (getcwd, sizeof(cwd) != NULL)
{
fprintf(stdout, "Current working dir: %s\n");
return 0;
}
printf("Please enter a string\n");
int ch = fgetc(stdin);
while (ch != EOF)
{
pid = fork();
if (pid == 0)
{
printf("Child Working");
}
else
printf("Child not working");
while (isspace(ch))
{
// If only 1 line of input allowed, then add
if (ch == '\n') return 0;;
ch = fgetc(stdin);
}
if (ch != EOF)
{
do
{
fputc(ch, stdout);
ch = fgetc(stdin);
}
while (ch != EOF && !isspace(ch));
fputc('\n', stdout);
}
}
return 0;
}
내가 지금까지 무엇입니까 출력은 아래 화면 캡처에 있습니다
또한 내 포크 프로세스는 단지 다른 쉘 명령을 처리 할 수있는 설정, 즉 비트가 혼란 죄송 경우 – user3358064