TIME,
PID
};
+enum {
+ OPT_HUMAN = CHAR_MAX + 1
+};
-static void do_shm (char format);
-static void print_shm (int id);
+static void do_shm (char format, int unit);
+static void print_shm (int id, int unit);
static void do_sem (char format);
static void print_sem (int id);
-static void do_msg (char format);
-
-void print_msg (int id);
+static void do_msg (char format, int unit);
+static void print_msg (int id, int unit);
static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
fputs(_(" -c, --creator show creator and owner\n"), out);
fputs(_(" -l, --limits show resource limits\n"), out);
fputs(_(" -u, --summary show status summary\n"), out);
+ fputs(_(" --human show sizes in human readable format\n"), out);
fprintf(out, USAGE_MAN_TAIL("ipcs(1)"));
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
{
int opt, msg = 0, sem = 0, shm = 0, id=0, print=0;
char format = NOTSPECIFIED;
+ int unit = IPC_UNIT_DEFAULT;
static const struct option longopts[] = {
{"id", required_argument, NULL, 'i'},
{"shmems", no_argument, NULL, 'm'},
{"creator", no_argument, NULL, 'c'},
{"limits", no_argument, NULL, 'l'},
{"summary", no_argument, NULL, 'u'},
+ {"human", no_argument, NULL, OPT_HUMAN},
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
case 'u':
format = STATUS;
break;
+ case OPT_HUMAN:
+ unit = IPC_UNIT_HUMAN;
+ break;
case 'h':
usage(stdout);
case 'V':
if (print) {
if (shm)
- print_shm (id);
+ print_shm (id, unit);
if (sem)
print_sem (id);
if (msg)
- print_msg (id);
+ print_msg (id, unit);
if (!shm && !sem && !msg )
usage (stderr);
} else {
printf ("\n");
if (shm) {
- do_shm (format);
+ do_shm (format, unit);
printf ("\n");
}
if (sem) {
printf ("\n");
}
if (msg) {
- do_msg (format);
+ do_msg (format, unit);
printf ("\n");
}
}
return EXIT_SUCCESS;
}
-static void do_shm (char format)
+static void do_shm (char format, int unit)
{
struct passwd *pw;
struct shm_data *shmds, *shmdsp;
if (ipc_shm_get_limits(&lim))
return;
printf (_("max number of segments = %ju\n"), lim.shmmni);
- printf (_("max seg size (kbytes) = %ju\n"), lim.shmmax / 1024);
- printf (_("max total shared memory (kbytes) = %ju\n"),
- (lim.shmall / 1024) * getpagesize());
- printf (_("min seg size (bytes) = %ju\n"), lim.shmmin);
+ ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
+ _("max seg size"), lim.shmmax, "\n", 0);
+ ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_KB : unit,
+ _("max total shared memory"),
+ lim.shmall * getpagesize(), "\n", 0);
+ ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
+ _("min seg size"), lim.shmmin, "\n", 0);
return;
}
case STATUS:
default:
printf (_("------ Shared Memory Segments --------\n"));
printf ("%-10s %-10s %-10s %-10s %-10s %-10s %-12s\n",
- _("key"),_("shmid"),_("owner"),_("perms"),_("bytes"),
+ _("key"),_("shmid"),_("owner"),_("perms"),
+ unit == IPC_UNIT_HUMAN ? _("size") : _("bytes"),
_("nattch"),_("status"));
break;
}
printf ("%-10d %-10.10s", shmdsp->shm_perm.id, pw->pw_name);
else
printf ("%-10d %-10u", shmdsp->shm_perm.id, shmdsp->shm_perm.uid);
- printf (" %-10o %-10lu %-10ld %-6s %-6s\n",
- shmdsp->shm_perm.mode & 0777,
- shmdsp->shm_segsz,
+ printf (" %-10o ", shmdsp->shm_perm.mode & 0777);
+ ipc_print_size(unit, NULL, shmdsp->shm_segsz, NULL, -10);
+ printf (" %-10ld %-6s %-6s\n",
shmdsp->shm_nattch,
shmdsp->shm_perm.mode & SHM_DEST ? _("dest") : " ",
shmdsp->shm_perm.mode & SHM_LOCKED ? _("locked") : " ");
return;
}
-static void do_msg (char format)
+static void do_msg (char format, int unit)
{
struct passwd *pw;
struct msg_data *msgds, *msgdsp;
return;
printf (_("------ Messages Limits --------\n"));
printf (_("max queues system wide = %d\n"), lim.msgmni);
- printf (_("max size of message (bytes) = %zu\n"), lim.msgmax);
- printf (_("default max size of queue (bytes) = %d\n"), lim.msgmnb);
+ ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
+ _("max size of message"), lim.msgmax, "\n", 0);
+ ipc_print_size(unit == IPC_UNIT_DEFAULT ? IPC_UNIT_BYTES : unit,
+ _("default max size of queue"), lim.msgmnb, "\n", 0);
return;
}
case STATUS:
printf (_("------ Messages Status --------\n"));
printf (_("allocated queues = %d\n"), msginfo.msgpool);
printf (_("used headers = %d\n"), msginfo.msgmap);
- printf (_("used space = %d bytes\n"), msginfo.msgtql);
+ ipc_print_size(unit, _("used space ="), msginfo.msgtql,
+ unit == IPC_UNIT_DEFAULT ? _(" bytes\n") : "\n", 0);
return;
}
case CREATOR:
printf (_("------ Message Queues --------\n"));
printf ("%-10s %-10s %-10s %-10s %-12s %-12s\n",
_("key"), _("msqid"), _("owner"), _("perms"),
- _("used-bytes"), _("messages"));
+ unit == IPC_UNIT_HUMAN ? _("size") : _("used-bytes"),
+ _("messages"));
break;
}
printf ("%-10d %-10.10s", msgdsp->msg_perm.id, pw->pw_name);
else
printf ("%-10d %-10u", msgdsp->msg_perm.id, msgdsp->msg_perm.uid);
- printf (" %-10o %-12ld %-12ld\n",
- msgdsp->msg_perm.mode & 0777,
- msgdsp->q_cbytes,
- msgdsp->q_qnum);
+ printf (" %-10o ", msgdsp->msg_perm.mode & 0777);
+ ipc_print_size(unit, NULL, msgdsp->q_cbytes, NULL, -12);
+ printf (" %-12ld\n", msgdsp->q_qnum);
break;
}
}
return;
}
-static void print_shm(int shmid)
+static void print_shm(int shmid, int unit)
{
struct shm_data *shmdata;
shmdata->shm_perm.cuid, shmdata->shm_perm.cgid);
printf(_("mode=%#o\taccess_perms=%#o\n"), shmdata->shm_perm.mode,
shmdata->shm_perm.mode & 0777);
- printf(_("bytes=%ju\tlpid=%u\tcpid=%u\tnattch=%jd\n"),
- shmdata->shm_segsz, shmdata->shm_lprid, shmdata->shm_cprid,
+ ipc_print_size(unit, unit == IPC_UNIT_HUMAN ? _("size=") : _("bytes="),
+ shmdata->shm_segsz, "\t", 0);
+ printf(_("lpid=%u\tcpid=%u\tnattch=%jd\n"),
+ shmdata->shm_lprid, shmdata->shm_cprid,
shmdata->shm_nattch);
printf(_("att_time=%-26.24s\n"),
shmdata->shm_atim ? ctime(&(shmdata->shm_atim)) : _("Not set"));
ipc_shm_free_info(shmdata);
}
-
-void print_msg(int msgid)
+void print_msg(int msgid, int unit)
{
struct msg_data *msgdata;
msgdata->msg_perm.uid, msgdata->msg_perm.uid,
msgdata->msg_perm.cuid, msgdata->msg_perm.cgid,
msgdata->msg_perm.mode);
- printf(_("cbytes=%jd\tqbytes=%jd\tqnum=%jd\tlspid=%d\tlrpid=%d\n"),
- msgdata->q_cbytes, msgdata->q_qbytes, msgdata->q_qnum,
+ ipc_print_size(unit, unit == IPC_UNIT_HUMAN ? _("csize=") : _("cbytes="),
+ msgdata->q_cbytes, "\t", 0);
+ ipc_print_size(unit, unit == IPC_UNIT_HUMAN ? _("qsize=") : _("qbytes="),
+ msgdata->q_qbytes, "\t", 0);
+ printf("qnum=%jd\tlspid=%d\tlrpid=%d\n",
+ msgdata->q_qnum,
msgdata->q_lspid, msgdata->q_lrpid);
printf(_("send_time=%-26.24s\n"),
msgdata->q_stime ? ctime(&msgdata->q_stime) : _("Not set"));