[질문] Pesudo Terminal에 대해서.....

익명 사용자의 이미지

학교 숙제로 멀티플렉서를 만들어야 하는데 넘 어려워용...

우선 저번까지 숙제로 만든 쉘이 있습니다...

실제 물리적인 터미널위에서 멀티플렉서가 돌면서...

필요한 만큰 쉘 프로세스를 포크합니다..

forkpty()시스템 콜로 쉘 프로세스는 포크하면서 하나의 pseudo terminal을

가지도록 합니다..

수도터미널을 가진 여러 쉘 프로세스중 하나에게 명령어를 보냅니다..

그러면 그 선택된 하나의 쉘에서 실행된 결과가 수도터미널의 마스터를 거쳐서

멀티플렉서가 읽은 다음에 실제 물리적인 터미널에 출력해주는 것입니다..

막히는 부분이 쉘 프로세스에게 명령을 전달하는 것입니다..

bash에선 "echo ls | bash"하면 ls의 결과가 나옵니다..

저도 멀티플렉서와 쉘 프로세스 사이에 파이프를 만들어서 전달을 했는데

안되네요...

다음은 쉘프로세스를 forkpty()로 수도터미널로 포크하고

파이프로 명령어를 전송하고 결과를 읽어서 출력하는 것인데...

execlp("ls", "ls");해서 하면 잘되거든요...

ls 결과가 멀티플렉서를 거쳐서 잘 나오는데...

제 한계입니다.. 아시는 분 도움 좀 주세요.. T.T

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

int main()
{
int master;
char slave[200];
pid_t child;

fd_set rfds;
struct timeval tv;
int retval;

char buf[4096];

char argv[2][4] = {"ls", "-al"};

int fd, pvc;

tv.tv_sec = 5;
tv.tv_usec = 0;

child = forkpty(&master, slave, NULL, NULL);
fprintf(stderr, "%s\n", slave);

mkfifo("./pvc", 0660);
pvc = open("./pvc", O_RDWR);

if(child == 0)
{
dup2(pvc, STDIN_FILENO);
execl("./nssh", "nssh");
fprintf(stderr, "%s\n", strerror(errno));
exit(-1);
}
else
{
write(pvc, "ls", strlen("ls") * sizeof(char));
FD_ZERO(&rfds);
FD_SET(master, &rfds);
retval = select(master + 1, &rfds, NULL, NULL, &tv);

if(FD_ISSET(master, &rfds))
{
fprintf(stderr, "ready\n");
while( read(master, buf, sizeof(buf)) > 0 )
fputs(buf, stdout);
}
}

exit(1);
}

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.