Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
Operating System - Tru64 Unix
Showing results for 
Search instead for 
Did you mean: 

How to use swapctl() function to list swap devices ???

Ali Humaidan
Occasional Advisor

How to use swapctl() function to list swap devices ???

Hi guys, this C program is driving me crazy for listing swap devices .. dont know what is the error .. Can anybody help me ???


int i, res;
struct swapent ent;
struct swapent* ent_ptr;
struct swaptable tb1;

tb1.swt_n = 10;
for (i=0; i<10; i++)
ent_ptr = malloc(sizeof(ent));
tb1.swt_ent[i] = *ent_ptr;
tb1.swt_ent[i].ste_path = malloc(sizeof(char[MAXPATHLEN]));
printf ("loc(swt_ent)=%p loc(path)=%p\n",

res = swapctl(SC_LIST, &tb1);
if (res>=0)
for (i=0; i {
/* This line is the source of error - if commented out everything runs fine */
printf ("%s", tb1.swt_ent[i].ste_path);

printf ("(%p) ", tb1.swt_ent[i].ste_path);
printf ("swap %d: size=%ld pages, free=%ld pages\n",
i, /*tb1.swt_ent[i].ste_path,*/
else perror ("swapctl");
Michael Schulte zur Sur
Honored Contributor

Re: How to use swapctl() function to list swap devices ???


can you specify, what kind of error you have? Compile error, wrong output or something else? I have no access to a computer right now, so I must guess.