15.2 Kernel Utilities

Mac OS X includes various utilities that interact with the kernel. With these utilities, you can debug a running kernel, load and unload kernel modules or extensions, or set kernel variables .

15.2.1 ddb

The ddb utility can debug a running kernel. It is not included with the current version of Mac OS X. If you want to use ddb , you can find its source code in the xnu (Darwin kernel) source code (http://www.opensource.apple.com/darwinsource/).

15.2.2 ktrace

Use ktrace to perform kernel tracing (tracing system calls and other operations) on a process. To launch a program and generate a kernel trace ( ktrace.out , which is not human-readable ), use ktrace command , as in ktrace emacs . Kernel tracing ends when you exit the process or disable tracing with ktrace -cp pid . You can get human readable output from a ktrace file with kdump .

15.2.3 Kernel Module Utilities

The following list describes utilities for manipulating kernel modules. For more information, see the kernel extension tutorials available at http://www.opensource.apple.com/projects/documentation/howto. These utilities must be run with superuser privileges:


kextload

Loads an extension bundle.


kextunload

Unloads an extension bundle.


kextstat

Displays the status of currently loaded kernel extensions. Table 15-5 describes this utility's output. Figure 15-6 shows sample output.

Table 15-5. Information displayed by kextstat

Item

number

Column

Description

1

 Index 

Index number of the loaded extension. Extensions are loaded in sequence; gaps in this sequence signify extensions that have been unloaded.

2

 Refs 

Number of references to this extension from other extensions.

3

 Address 

Kernel space address of the extension.

4

 Size 

Amount of kernel memory (in bytes) used by the extension.

5

 Wired 

Amount of wired kernel memory (in bytes) used by the extension.

6

 Name (Version) 

Name and version of the extension.

7

 <Linked Against> 

Index of kernel extensions to which this extension refers.


Figure 15-6. Partial output of kextstat
figs/mug2_1506.gif

15.2.4 sysctl

sysctl is a standard BSD facility for configuring kernel state variables. Use sysctl name to display a variable name, as in sysctl kern.ostype . Use sysctl -a to display all variables. If you have superuser privileges, you can set a variable with sysctl -w name = value .

Table 15-6 lists the sysctl variables on Mac OS X. See the sysctl(3) manpage for a description of the sysctl system call and more detailed information on the kernel state variables.

Table 15-6. sysctl's kernel state variables

Name

Type

Writable

Description

hw.activecpu

 int 
 no 

The number of CPUs currently active and available (may be affected by power management settings).

hw.busfrequency

 int 
 no 

Bus frequency in hertz. Divide by one million for a megahertz figure.

hw.busfrequency_max

 int 
 no 

Maximum bus frequency in hertz.

hw.busfrequency_min

 int 
 no 

Minimum bus frequency in hertz.

hw.byteorder

 int 
 no 

Variable that returns 4321, showing the ordering of four bytes on the PowerPC platform.

hw.cachelinesize

 int 
 no 

The cache line size in bytes.

hw.cpufrequency

 int 
 no 

CPU frequency in hertz. Divide by one million for a megahertz figure.

hw.cpufrequency_max

 int 
 no 

Maximum CPU frequency in hertz.

hw.cpufrequency_min

 int 
 no 

Minimum CPU frequency in hertz.

hw.cpusubtype

 int 
 no 

The mach-o subtype of the CPU (see /System/Library/Frameworks/Kernel.framework/Versions/ A/Headers/mach/machine.h ).

hw.cputype

 int 
 no 

The mach-o type of the CPU.

hw. epoch

 int 
 no 

Variable that indicates whether your hardware is "New World" or "Old World." Old World Macintoshes (pre-G3) have a value of .

hw.l1dcachesize

 int 
 no 

Level 1 data cache size in bytes.

hw.l1icachesize

 int 
 no 

Level 1 instruction cache size in bytes.

hw.l2cachesize

 int 
 no 

Level 2 cache size in bytes.

hw.l2settings

 int 
 no 

Level 2 cache settings.

hw.l3cachesize

 int 
 no 

Level 3 cache size in bytes.

hw.l3settings

 int 
 no 

Level 3 cache settings.

hw.machine

 string 
 no 

Machine class ( Power Macintosh on most systems).

hw.model

 string 
 no 

Machine model.

hw.ncpu

 int 
 no 

Number of CPUs.

hw.optional. altivec

 int 
 no 

Indicates whether AltiVec is enabled.

hw.optional.datastreams

 int 
 no 

Indicates whether PowerPC data stream instructions are supported by the CPU.

hw.optional.dcba

 int 
 no 

Indicates whether the PowerPC DCBA instruction is supported by the CPU.

hw.optional.floatingpoint

 int 
 no 

Indicates whether floating point operations are supported by the CPU.

hw.optional.graphicsops

 int 
 no 

Indicates whether graphics operations are supported by the CPU.

hw.optional.stfiwx

 int 
 no 

Indicates whether the PowerPC STFIWX instruction is supported by the CPU.

hw.pagesize

 int 
 no 

Software page size in bytes.

hw.physmem

 int 
 no 

Physical memory in bytes.

hw.tbfrequency

 int 
 no 

The base frequency used by Mac OS X for its timing services.

hw.usermem

 int 
 no 

Non-kernel memory.

hw.vectorunit

 int 
 no 

Variable that indicates whether you are running on an AltiVec-enabled CPU.

kern.aiomax

 int 
 no 

Maximum AIO requests .

kern.aioprocmax

 int 
 no 

Maximum AIO requests per process.

kern.aiothreads

 int 
 no 

Maximum number of AIO worker threads.

kern.argmax

 int 
 no 

Maximum number of arguments supported by exec ( ) .

kern.boottime

 struct timeval 
 no 

The time when the system was booted .

kern.clockrate

 struct clockinfo 
 no 

System clock timings.

kern. dummy

 n/a 
 n/a 

Unused.

kern.hostid

 int 
 yes 

Host identifier.

kern.hostname

 string 
 yes 

Hostname.

kern.ipc.*

 various 
 n/a 

Various IPC settings.

kern.job_control

 int 
 no 

Variable that indicates whether job control is available.

kern.maxfiles

 int 
 yes 

Maximum number of open files.

kern.maxfilesperproc

 int 
 yes 

Maximum number of open files per process .

kern.maxproc

 int 
 yes 

Maximum number of simultaneous processes.

kern.maxprocperuid

 int 
 yes 

Maximum number of simultaneous processes per user .

kern.maxvnodes

 int 
 yes 

Maximum number of vnodes.

kern.netboot

 int 
 no 

Variable that indicates whether the system booted via NetBoot.

kern.ngroups

 int 
 no 

Maximum number of supplemental groups.

kern.nisdomainname

 string 
 yes 

NIS domain name.

kern.osrelease

 string 
 no 

Operating system release version.

kern.osrevision

 int 
 no 

Operating system revision.

kern.ostype

 string 
 no 

Operating system name.

kern.posix1version

 int 
 no 

The version of POSIX 1003.1 with which the system attempts to comply .

kern.saved_ids

 int 
 no 

This is set to 1 if saved set- group and set-user IDs are available.

kern. securelevel

 int 
 increment only 

The system security level.

kern.symfile

 string 
 no 

The kernel symbol file.

kern.sysv.*

 various 
 n/a 

System V semaphore settings. See /System/Library/Frameworks/Kernel.framework/Versions/A/Headers/sys/sysctl.h .

kern.sysv.shmall

 int 
 yes 

The maximum size of a shared memory segment.

kern.sysv.shmmax

 int 
 yes 

The maximum number of shared memory pages.

kern.sysv.shmmin

 int 
 yes 

The maximum number of shared memory segments per process.

kern.sysv.shmmni

 int 
 yes 

The maximum number of shared memory segments.

kern.sysv.shmseg

 int 
 yes 

The minimum size of a shared memory segment.

kern.version

 string 
 no 

The kernel version string.

net.appletalk.routermix

   

Description unavailable at time of printing. Please see the errata at http://www.oreilly.com/catalog/mpantherunix/.

net.inet.*

 various 
 n/a 

IPv4 settings.

net.inet6.*

 various 
 n/a 

IPv6 settings.

net.key.*

 various 
 n/a 

IPSec key management settings.

net.link. ether .inet.*

 various 
 n/a 

Ethernet settings.

net.local.*

 various 
 n/a 

Description unavailable at time of printing. Please see the errata at http://www.oreilly.com/catalog/mpantherunix/.

user.bc_base_max

 int 
 no 

Maximum ibase/obase available in the bc calculator.

user.bc_dim_max

 int 
 no 

Maximum array size available in the bc calculator.

user.bc_scale_max

 int 
 no 

Maximum scale value available in the bc calculator.

user.bc_string_max

 int 
 no 

Maximum string length available in the bc calculator.

user.coll_weights_max

 int 
 no 

Maximum number of weights that can be used with LC_COLLATE in the locale definition file.

user.cs_path

 string 
 no 

Value for PATH that can find all the standard utilities.

user.expr_nest_max

 int 
 no 

Maximum number of expressions you can nest within parentheses using expr .

user.line_max

 int 
 no 

Maximum length in bytes of an input line used with a text-processing utility.

user.posix2_c_bind

 int 
 no 

Variable that returns 1 if the C development environment supports the POSIX C Language Bindings Option; otherwise , the result will be .

user.posix2_c_dev

 int 
 no 

Variable that returns 1 if the C development environment supports the POSIX C Language Development Utilities Option; otherwise, the result will be .

user.posix2_char_term

 int 
 no 

Variable that returns 1 if the systems supports at least one terminal type specified in POSIX 1003.2; otherwise, the result will be .

user.posix2_fort_dev

 int 
 no 

Variable that returns 1 if the system supports the POSIX FORTRAN Development Utilities Option; otherwise, the result will be .

user.posix2_fort_run

 int 
 no 

Variable that returns 1 if the system supports the POSIX FORTRAN Runtime Utilities Option; otherwise, the result will be .

user.posix2_localedef

 int 
 no 

Variable that returns 1 if the system allows you to create locale; otherwise, the result will be .

user.posix2_sw_dev

 int 
 no 

Variable that returns 1 if the system supports the POSIX Software Development Utilities Option; otherwise, the result will be .

user.posix2_upe

 int 
 no 

Variable that returns 1 if the system supports the POSIX User Portable Utilities Option; otherwise, the result will be .

user.posix2_version

 int 
 no 

Variable that returns the POSIX 1003.2 version with which the system attempts to comply.

user.re_dup_max

 int 
 no 

Maximum repeated occurrences of a regular expression when using interval notation.

user.stream_max

 int 
 no 

Maximum number of streams a process may have open.

user.tzname_max

 int 
 no 

Maximum number of types supported for a time zone name.

vfs.*

 various 
 n/a 

Various VFS settings.

vm.loadavg

 string 
 no 

Current load average.




Mac OS X Panther for Unix Geeks
Mac OS X Panther for Unix Geeks
ISBN: 0596006071
EAN: 2147483647
Year: 2003
Pages: 212

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net