mirror of
https://github.com/ada-dmitry/prog.l_ada.git
synced 2026-09-26 02:00:14 +00:00
added sock20
This commit is contained in:
@@ -1,60 +1,26 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <sys/sem.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/sem.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
static void
|
||||
usage(const char *pname)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [-cx] pathname proj-id num-sems\n",
|
||||
pname);
|
||||
fprintf(stderr, " -c Use IPC_CREAT flag\n");
|
||||
fprintf(stderr, " -x Use IPC_EXCL flag\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#define errExit(msg) \
|
||||
do \
|
||||
{ \
|
||||
perror(msg); \
|
||||
exit(EXIT_FAILURE); \
|
||||
} while (0)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int semid, nsems, flags, opt;
|
||||
key_t key;
|
||||
union semun
|
||||
{ /* Used in calls to semctl() */
|
||||
int val;
|
||||
struct semid_ds *buf;
|
||||
unsigned short *array;
|
||||
#if defined(__linux__)
|
||||
struct seminfo *__buf;
|
||||
#endif
|
||||
};
|
||||
|
||||
flags = 0;
|
||||
while ((opt = getopt(argc, argv, "cx")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'c':
|
||||
flags |= IPC_CREAT;
|
||||
break;
|
||||
case 'x':
|
||||
flags |= IPC_EXCL;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
}
|
||||
}
|
||||
|
||||
if (argc != optind + 3)
|
||||
usage(argv[0]);
|
||||
|
||||
key = ftok(argv[optind], argv[optind + 1][0]);
|
||||
if (key == -1)
|
||||
{
|
||||
perror("ftok");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
nsems = atoi(argv[optind + 2]);
|
||||
|
||||
semid = semget(key, nsems, flags | 0600);
|
||||
if (semid == -1)
|
||||
{
|
||||
perror("semget");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("ID = %d\n", semid);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
#define MEM_SIZE 4096
|
||||
|
||||
Reference in New Issue
Block a user