pipe와 fork를 사용한 프로그램..

itoti의 이미지

void Player::Play(const char *mp3name)
{
  if (state == PAUSED && mp3name && Player::mp3name && \
      !strcmp(mp3name,Player::mp3name))
    Pause();
  else
    if (mp3name) { 
      if (state != STOPPED) Stop();
      
      if(Player::mp3name) delete[] mp3name;
      Player::mp3name = strdup(mp3name);
      
      int pipes[2];
      int fork_res;

      if (pipe(pipes) == 0) {
	fork_res = fork();
	if (fork_res == -1) {
	  cerr << "Can't fork !!\n";
	  exit(1);
	}
	if (fork_res == 0) {
	  if (close(2)) cerr << "Can't close stderr\n";
	  dup2(pipes[1],2);
	  close(pipes[0]);
	  close(pipes[1]);
	  
	  char *str = new char[128];
	  sprintf(str,"%d",buffersize);
	  execlp(playercommand,playercommand,"",mp3name,(char *)0);
	  cerr << "Can't execlp " << playercommand << "\n";
	  exit(1);
	} else {
	  close(pipes[1]);
	  char *buf = new char[2048+1];
	  char *p; char c;
	  int failed = 0;
	  for (int i = 0; i< 8; i++) 
	  {
	    c='\0'; 
	    p=buf; 
	    while (c != '\n') 
	    { 
	      read(pipes[0],&c,1); *p++ = c;
	    } 
	    *p = '\0';
	    if(i==3 && *buf != '\n') {failed =1; i=8;}
	    if(i==5 && *buf == 'I') {failed =1; i=8;}
	  }
	  delete[] buf;
	  close(pipes[0]);
	  sleep(1); 
	  playerpid = fork_res;
	  state = PLAYING;
	  emit Playing();
	  if (failed) Stop();
	}
      }
    }
}

프로세서를 이용하여 mp3플레이 하는 소스의 일 부분인데요..

여기서 플레이가 안되고 멈추게 되는 데요..

pipe가 생성이 안되는 것 같은데.. 그이유는 무엇인가요??

플레이를 하면 세그멘테이션 오류가 뜨거나 그냥 멈춰 버립니다...

혹시 이유를 아시거나..

주석을 좀 달아 주시겠어요..

프로세서 관련 코드를 처음 접해봐서.. 너무 어렵네요...

감사합니다.

댓글 달기

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
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.