semopsid.c

来自「《UNIX进程间通信》中的代码」· C语言 代码 · 共 39 行

C
39
字号
#include	"unpipc.h"intmain(int argc, char **argv){	int		c, i, flag, semid, nops;	struct sembuf	*ptr;	flag = 0;	while ( (c = Getopt(argc, argv, "nu")) != -1) {		switch (c) {		case 'n':			flag |= IPC_NOWAIT;		/* for each operation */			break;		case 'u':			flag |= SEM_UNDO;		/* for each operation */			break;		}	}	if (argc - optind < 2)			/* argc - optind = #args remaining */		err_quit("usage: semops [ -n ] [ -u ] <id> operation ...");	semid = atol(argv[optind]);	optind++;	nops = argc - optind;		/* 4allocate memory to hold operations, store, and perform */	ptr = Calloc(nops, sizeof(struct sembuf));	for (i = 0; i < nops; i++) {		ptr[i].sem_num = i;		ptr[i].sem_op = atoi(argv[optind + i]);	/* <0, 0, or >0 */		ptr[i].sem_flg = flag;	}	Semop(semid, ptr, nops);	exit(0);}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?