⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 semopsid.c

📁 这是unix网络编程一书的源代码希望能对大家的学习提供一种便利
💻 C
字号:
#include	"unpipc.h"

int
main(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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -