UNIX Hints & Hacks

ContentsIndex

Chapter 6: File Management

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

6.1 Copy Files with Permissions and Time Stamps

 

6.5 Finding Files with grep

 

6.8 Moving and Renaming Groups of Files

 

6.11 Splitting Files

6.2 Copy Files Remotely

 

6.6 Multiple grep

 

6.9 Stripping the Man Pages

 

6.12 Limit the Size of the Core

6.3 Which tmp Is a Good Temp?

 

6.7 Executing Commands Recursively with find

 

6.10 Clean Up DOS Files

 

6.13 uuencode and uudecode

6.4 Dealing with Symbolic Links

 

 

 

 

 

 

 

6.12 Limit the Size of the Core

6.12.1 Description

6.12.1 Description

The size of core files can be controlled with the use of the limit command.

Flavors: AT&T, some BSD

Shells: csh, tcsh

Syntax:

limit coredumpsize blocks

The limit command allows you to set certain restrictions on the system resources available to the current shell. Here is a set of system resources that can be modified for the shell:

rocket 69% limit
cputime         unlimited
filesize        unlimited
datasize        524288 kbytes
stacksize       65536 kbytes
coredumpsize    unlimited
memoryuse       57880 kbytes
descriptors     200
vmemoryuse      524288 kbytes

In looking at the value set for the coredumpsize, if the system were to dump a core file right now for an application running under the current shell, it could potentially be a file as large as the amount of memory in the system. It would be an unlimited amount. If you want to limit the size of future core files that might get dumped by the system under the current running shell, use the limit command.

rocket 70% limit coredumpsize 1000

This can be placed at the beginning of any script or in the startup script of a shell. You can test to make sure this works on your system by setting the coredumpsize, starting a process, forcing a core dump on the process, and checking the size of the core file.

rocket 71% limit coredumpsize 1000
rocket 72% limit coredumpsize
coredumpsize    1000 kbytes

Set the limit of coredumpsize to 1000KB. This ensures that the core file is never any larger than 1000KB.

rocket 73% sleep 100 &
[1] 16965

Issue a sleep command in the background for 100 seconds. Make note of the process ID (PID), so you can kill it right away.

rocket 74% kill -SEGV 16965
[1]    Segmentation fault   sleep 100 (core dumped)

Send a kill request to force the process to dump a core file on exiting the process.

rocket 75% ls -al core
-rw-r--r--    1 apps user      99420 Nov 28 12:54 core
rocket 76% file core
core:    core dump of 'sleep'

You can now see that the core file never grows over the 1000KB limit set on it. If a limit size of 0 is set for the coredumpsize, a core file is never created.

rocket 77% rm core
rocket 78% limit coredumpsize 0
rocket 79% sleep 100 &
[1] 16971
rocket 80% kill -SEGV 16971
[1]    Segmentation fault   sleep 100
rocket 81% ls -al core
Cannot access core: No such file or directory

Reason

If you need to modify the size of the core file and you are unconcerned about the size when an application or program crashes, set the limit size on the core file.

Real World Experience

Often you find the disk space on workstations reaching capacity. In some cases, if the root filesystem fills up, the system is sluggish or might even crash. If you know that there is a strong chance that the disks would be full if a core dump were to take place, you might want to set the limit. In many cases, the message logging system catches any major errors, such as memory parity or disk I/O errors.

If the coredumpsize is set to 0 and an application or a program keeps crashing consistently, free up some disk space, change the limit of the coredumpsize back to unlimited, and let the application crash again so you can get a copy of the core dump.

I have seen some specific applications have 1GB of RAM with a 2GB internal system disk. When applications crashed there was no room for a core file, so I had to rely on the system logs for hardware errors and the programmers were stuck without core files to diagnose the software problems.

Other Resources

Man pages:

kill, limit

UNIX Hints & Hacks

ContentsIndex

Chapter 6: File Management

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

6.1 Copy Files with Permissions and Time Stamps

 

6.5 Finding Files with grep

 

6.8 Moving and Renaming Groups of Files

 

6.11 Splitting Files

6.2 Copy Files Remotely

 

6.6 Multiple grep

 

6.9 Stripping the Man Pages

 

6.12 Limit the Size of the Core

6.3 Which tmp Is a Good Temp?

 

6.7 Executing Commands Recursively with find

 

6.10 Clean Up DOS Files

 

6.13 uuencode and uudecode

6.4 Dealing with Symbolic Links

 

 

 

 

 

 

 

© Copyright Macmillan USA. All rights reserved.