Friday, September 30, 2011

Pipe a chain of processes

Create a chain of processes which are piped hand by hand, and write whatever read from stdin of the beginning process to stdout of the ending process.


#include <sys/types.h>
#include <sys/wait.h>
#include <iostream>
#include <unistd.h>


using namespace std;

int main() {
 
  // make sure at least one command

  int fd[10][2];

  pid_t pid;

  int i = 0;

  int count = 0;

  char c;

  for (; i < 4; ++i) {
    pipe (fd[i]);
   
    pid = fork();
   
    if (pid == 0) {
      dup2 (fd[i][0], 0);

      if (i > 0) {
dup2 (fd[i-1][1], 1);
      }
      else {
close (fd[i][1]);
      }

      while ((count = read(0, &c, 1)) > 0)
write(1, &c, 1);
     
      cout << "this is child process " << i << endl;

      break;
    }
    else {
      cout << "this is parent process " << i << endl;

      continue;
    }
  }
 
  if (pid) {
    close (fd[i-1][0]);

    while ((count = read(0, &c, 1)) > 0)
      write(1, &c, 1);
   
    cout << "this is final parent " << endl;
   
    waitpid (pid, NULL, 0);
  }

  return 0;
}

Monday, September 26, 2011

In F15, you may be faced with Aw, snap! in Chrome when it loading some web app like igoolge, google doc, etc.
The following method can fix it simply.

We are trying to control what the chrome-sandbox is allowed to do, since it is setuid. The bug that you are seeing is caused by a file/directory being created in the homedir with the wrong label on it. In F15 we did not have policycoreutils-restorecond installed by default, which would have fixed the mislabeled directory. We can add this to a comps file to make sure it gets installed in the future. In F16 we have the ability to label these files/directories correctly on creation.
The quick fix is to execute the following command:
restorecon -R ~/.config
The command also solves the problem where the Xmarks Bookmarks Synchronizer and Delicious Bookmarks Extensions keeps on crashing on Chrome on Fedora 15.
From: 
http://blog.randell.ph