<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=ISO-8859-1"/><linkrel="stylesheet"type="text/css"href="../libvirt.css"/><linkrel="SHORTCUT ICON"href="/32favicon.png"/><title>Libvirt set of C code examples</title></head><body><divid="container"><divid="intro"><divid="adjustments"></div><divid="pageHeader"></div><divid="content2"><h1class="style1">Libvirt set of C code examples</h1><p> The examples are stored per section depending on the main focus
of the example:</p><ul><li><p><ahref="#Informations">Informations</a> :</p><ul><li><ahref="#info1.c">info1.c</a>: Extract informations about Xen domain 0</li></ul></li><li><p><ahref="#Scheduling">Scheduling</a> :</p><ul><li><ahref="#suspend.c">suspend.c</a>: Suspend a domain and then resume its execution</li></ul></li></ul><p> Getting the compilation options and libraries dependancies needed
install</i> step or when installing the libvirt development package:</p><pre>gcc -o example example.c `pkg-config libvirt --libs`</pre><h2><aname="Informations"id="Informations"></a>Informations Examples</h2><h3><aname="info1.c"href="info1.c"id="info1.c">info1.c</a>: Extract informations about Xen domain 0</h3><p>Demonstrate the basic use of the library to connect to the hypervisor and extract domain informations.</p><p>Uses:</p><ul><li> line 29: Function <ahref="../html/libvirt-libvirt.html#virConnectOpenReadOnly">virConnectOpenReadOnly</a> from libvirt.h</li><li> line 36: Function <ahref="../html/libvirt-libvirt.html#virDomainLookupByID">virDomainLookupByID</a> from libvirt.h</li><li> line 43: Function <ahref="../html/libvirt-libvirt.html#virDomainGetInfo">virDomainGetInfo</a> from libvirt.h</li><li> line 53: Function <ahref="../html/libvirt-libvirt.html#virDomainFree">virDomainFree</a> from libvirt.h</li><li> line 55: Function <ahref="../html/libvirt-libvirt.html#virConnectClose">virConnectClose</a> from libvirt.h</li></ul><p>Usage:</p><p>info1</p><p>Author: Daniel Veillard</p><h2><aname="Scheduling"id="Scheduling"></a>Scheduling Examples</h2><h3><aname="suspend.c"href="suspend.c"id="suspend.c">suspend.c</a>: Suspend a domain and then resume its execution</h3><p>Demonstrate the basic use of the library to suspend and resume a domain. If no id is given on the command line this script will suspend and resume the first domain found which is not Domain 0.</p><p>Uses:</p><ul><li> line 31: Function <ahref="../html/libvirt-libvirt.html#virDomainGetInfo">virDomainGetInfo</a> from libvirt.h</li><li> line 50: Function <ahref="../html/libvirt-libvirt.html#virDomainLookupByID">virDomainLookupByID</a> from libvirt.h</li><li> line 62: Function <ahref="../html/libvirt-libvirt.html#virDomainSuspend">virDomainSuspend</a> from libvirt.h</li><li> line 73: Function <ahref="../html/libvirt-libvirt.html#virDomainResume">virDomainResume</a> from libvirt.h</li><li> line 93: Function <ahref="../html/libvirt-libvirt.html#virDomainFree">virDomainFree</a> from libvirt.h</li><li> line 100: Function <ahref="../html/libvirt-libvirt.html#virConnectOpenReadOnly">virConnectOpenReadOnly</a> from libvirt.h</li><li> line 111: Function <ahref="../html/libvirt-libvirt.html#virConnectListDomains">virConnectListDomains</a> from libvirt.h</li><li> line 132: Function <ahref="../html/libvirt-libvirt.html#virConnectClose">virConnectClose</a> from libvirt.h</li></ul><p>Usage:</p><p>suspend [id]</p><p>Author: Daniel Veillard</p></div></div><divclass="linkList2"><divclass="llinks2"><h3class="links2"><span>main menu</span></h3><ul><li><ahref="../index.html">Home</a></li><li><ahref="../html/index.html">API Menu</a></li><li><ahref="../examples/index.html">C code examples</a></li><li><ahref="../ChangeLog.html">Recent Changes</a></li></ul></div><divclass="llinks2"><h3class="links2"><span>related links</span></h3><ul><li><ahref="https://www.redhat.com/archives/libvir-list/">Mail archive</a></li><li><ahref="https://bugzilla.redhat.com/bugzilla/buglist.cgi?product=Fedora+Core&component=libvirt&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&bug_status=MODIFIED&short_desc_type=allwordssubstr&short_desc=&long_desc_type=allwordssubstr">Open bugs</a></li><li><ahref="http://virt-manager.et.redhat.com/">virt-manager</a></li><li><ahref="http://search.cpan.org/~danberr/Sys-Virt-0.1.0/">Perl bindings</a></li><li><ahref="http://libvirt.org/ocaml/">OCaml bindings</a></li><li><ahref="http://libvirt.org/ruby/">Ruby bindings</a></li><li><ahref="http://www.cl.cam.ac.uk/Research/SRG/netos/xen/index.html">Xen project</a></li><li><formaction="../search.php"enctype="application/x-www-form-urlencoded"method="get"><inputname="query"type="text"size="12"value="Search..."/><inputname="submit"type="submit"value="Go"/></form></li><li><ahref="http://xmlsoft.org/"><imgsrc="../Libxml2-Logo-90x34.gif"alt="Made with Libxml2 Logo"/></a></li></ul><pclass="credits">Graphics and design by <ahref="mail:dfong@redh