}
        } else {
                attr->inherit        = inherit;
-               attr->disabled       = 1;
-               attr->enable_on_exec = 1;
+               if (target_pid == -1) {
+                       attr->disabled = 1;
+                       attr->enable_on_exec = 1;
+               }
 
                fd[0][counter] = sys_perf_event_open(attr, pid, -1, -1, 0);
                if (fd[0][counter] < 0 && verbose)
        unsigned long long t0, t1;
        int status = 0;
        int counter;
-       int pid = target_pid;
+       int pid;
        int child_ready_pipe[2], go_pipe[2];
-       const bool forks = (target_pid == -1 && argc > 0);
+       const bool forks = (argc > 0);
        char buf;
 
        if (!system_wide)
        }
 
        if (forks) {
-               if ((pid = fork()) < 0)
+               if ((child_pid = fork()) < 0)
                        perror("failed to fork");
 
-               if (!pid) {
+               if (!child_pid) {
                        close(child_ready_pipe[0]);
                        close(go_pipe[1]);
                        fcntl(go_pipe[0], F_SETFD, FD_CLOEXEC);
                        exit(-1);
                }
 
-               child_pid = pid;
-
                /*
                 * Wait for the child to be ready to exec.
                 */
                close(child_ready_pipe[0]);
        }
 
+       if (target_pid == -1)
+               pid = child_pid;
+       else
+               pid = target_pid;
        for (counter = 0; counter < nr_counters; counter++)
                create_perf_stat_counter(counter, pid);
 
                close(go_pipe[1]);
                wait(&status);
        } else {
-               while(!done);
+               while(!done) sleep(1);
        }
 
        t1 = rdclock();
 
 static void skip_signal(int signo)
 {
-       if(target_pid != -1)
+       if(child_pid == -1)
                done = 1;
 
        signr = signo;