Operating System - Tru64 Unix
1828285 Members
3320 Online
109975 Solutions
New Discussion

Re: 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 ???

#include
#include
#include
#include

main()
{
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",
&tb1.swt_ent[i],
tb1.swt_ent[i].ste_path);
}

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,*/
tb1.swt_ent[i].ste_pages,
tb1.swt_ent[i].ste_free);
}
else perror ("swapctl");
}
1 REPLY 1
Michael Schulte zur Sur
Honored Contributor

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

Hi,

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.

greetings,

Michael