Example #1
0
int main(void)
{
	int n;
	int fd[2];
	pid_t pid;
	char line[MAXLINE];

	if (pipe(fd) < 0)
		err_sys("pipe error");
	pid = fork();
	switch (pid) {
		case -1: err_sys("fork error");
		case  0: write(STDOUT_FILENO, "child:", 7);
				 close(fd[1]);
				 n = read(fd[0], line, MAXLINE);
				 write(STDOUT_FILENO, line, n);
		default: write(STDOUT_FILENO, "parent:", 8);
				 close(fd[0]);
				 write(fd[1], "hello world\n", 12);
				 break;
	}

	if (pid > 0) {
		pid_t child;
		int status;

		child = wait(&status);
		pr_wait(status);
	}
	exit(0);
}
Example #2
0
/*exec commod and printf exec times*/
static void do_cmd(char *cmd)
{
	struct tms tmsstart, tmsend;
	clock_t start, end;
	int status;

	printf("\ncommond: %s\n", cmd);

	if ((start = times(&tmsstart)) == -1)
		err_sys("times error");

	if ((status = system(cmd)) < 0)
		err_sys("syster() error");

	if ((end = times(&tmsend)) == -1)
		err_sys("times error");

	pr_times(end - start, &tmsstart, &tmsend);
	pr_wait(status);
}
Example #3
0
File: main.c Project: jjzhang/dlm
static void print_lkb(char *line, struct rinfo *ri)
{
	struct lkb lkb;
	char type[4];
	int rv;

	rv = sscanf(line, "%s %x %d %x %u %llu %x %x %d %d %d %d %d %d %u %llu %llu",
		    type,
		    &lkb.id,
		    &lkb.nodeid,
		    &lkb.remid,
		    &lkb.ownpid,
		    (unsigned long long *)&lkb.xid,
		    &lkb.exflags,
		    &lkb.flags,
		    &lkb.status,
		    &lkb.grmode,
		    &lkb.rqmode,
		    &lkb.highbast,
		    &lkb.rsb_lookup,
		    &lkb.wait_type,
		    &lkb.lvbseq,
		    (unsigned long long *)&lkb.timestamp,
		    (unsigned long long *)&lkb.time_bast);

	ri->lkb_count++;

	if (lkb.status == DLM_LKSTS_GRANTED) {
	       	if (!ri->print_granted++)
			printf("Granted\n");
		ri->lkb_granted++;
	}
	if (lkb.status == DLM_LKSTS_CONVERT) {
		if (!ri->print_convert++)
			printf("Convert\n");
		ri->lkb_convert++;
	}
	if (lkb.status == DLM_LKSTS_WAITING) {
	       	if (!ri->print_waiting++)
			printf("Waiting\n");
		ri->lkb_waiting++;
	}
	if (lkb.rsb_lookup) {
	       	if (!ri->print_lookup++)
			printf("Lookup\n");
		ri->lkb_lookup++;
	}

	if (lkb.wait_type)
		ri->lkb_wait_msg++;

	if (!ri->nodeid) {
		if (lkb.nodeid)
			ri->lkb_master_copy++;
		else
			ri->lkb_local_copy++;
	} else {
		ri->lkb_process_copy++;
	}

	printf("%08x %s %s %s %s %s\n",
	       lkb.id, pr_grmode(&lkb), pr_rqmode(&lkb),
	       pr_remote(&lkb, ri), pr_wait(&lkb),
	       (verbose && wide) ? pr_verbose(&lkb) : "");

	if (verbose && !wide)
		printf("%s\n", pr_verbose(&lkb));
}