# Libvirt set of C code examples

The examples are stored per section depending on the main focus of the example:

- Informations :

  - info1.c: Extract information about Xen domain 0

- Scheduling :

  - suspend.c: Suspend a domain and then resume its execution

Getting the compilation options and libraries dependancies needed to generate binaries from the examples is best done on Linux/Unix by using the pkg-config data which should have been installed as part of make install step or when installing the libvirt development package:

    gcc -o example example.c `pkg-config libvirt --libs`

## Informations Examples

### info1.c: Extract information about Xen domain 0

Demonstrate the basic use of the library to connect to the hypervisor and extract domain information.

Uses:

- line 29: Function virConnectOpenReadOnly from libvirt.h
- line 36: Function virDomainLookupByID from libvirt.h
- line 43: Function virDomainGetInfo from libvirt.h
- line 53: Function virDomainFree from libvirt.h
- line 55: Function virConnectClose from libvirt.h

Usage:

info1

Author: Daniel Veillard

## Scheduling Examples

### suspend.c: Suspend a domain and then resume its execution

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.

Uses:

- line 31: Function virDomainGetInfo from libvirt.h
- line 50: Function virDomainLookupByID from libvirt.h
- line 62: Function virDomainSuspend from libvirt.h
- line 73: Function virDomainResume from libvirt.h
- line 93: Function virDomainFree from libvirt.h
- line 100: Function virConnectOpenReadOnly from libvirt.h
- line 111: Function virConnectListDomains from libvirt.h
- line 132: Function virConnectClose from libvirt.h

Usage:

suspend [id]

Author: Daniel Veillard

### main menu

- Home
- API Menu
- C code examples
- Recent Changes

### related links

- Mail archive
- Open bugs
- virt-manager
- Perl bindings
- OCaml bindings
- Ruby bindings
- Xen project

Graphics and design by Diana Fong