Linux ESPIPE (errno 29) — Illegal Seek on Pipe/Socket
About Linux ESPIPE (errno 29)
Linux ESPIPE error occurs when a program tries to seek (reposition) within a pipe, socket, or FIFO which does not support random access. This guide covers everything you need to know about this topic, including common causes, step-by-step solutions, and answers to frequently asked questions.
Here are the key things to understand: ESPIPE (errno 29) means lseek() was called on a file descriptor that does not support seeking. Pipes, sockets, FIFOs, and some special files are sequential-only streams. Common when a program designed for regular files receives a pipe via shell redirection. Applications that check file size (fstat then lseek to end) fail on pipe input. Some compression tools need to seek backward and cannot work with pipes. Understanding these fundamentals will help you diagnose and resolve this issue more effectively.
The most common reasons this occurs include: Program using lseek() on stdin when input is piped (cat file | program). Application trying to read file size of a pipe or socket. Compression/archive tool needing random access but receiving a stream. Database trying to seek within a network socket connection. Shell script using seek operations on a FIFO special file. Identifying the root cause is the first step toward finding the right solution.
To resolve this, follow these recommended steps: Use a temporary file instead of a pipe: command > /tmp/data && program /tmp/data. Use process substitution: program <(command) — creates a regular file descriptor on some systems. For input from pipe: buffer entire input to a temp file first, then process. Check if the program supports reading from stdin without seeking (--stdin or - flag). Use named pipe with appropriate buffering: mkfifo /tmp/mypipe. If these steps do not resolve the issue, consider consulting additional resources or a qualified professional.
This article is part of our Linux Error Codes collection on Error Codes Wiki. We provide comprehensive, up-to-date information to help you find solutions quickly.
Quick Answer
Why can I not seek on a pipe?
Pipes are one-directional streams with no random access. Data flows from writer to reader sequentially — there is nothing to seek to.
Overview
Linux ESPIPE error occurs when a program tries to seek (reposition) within a pipe, socket, or FIFO which does not support random access.
Key Details
- ESPIPE (errno 29) means lseek() was called on a file descriptor that does not support seeking
- Pipes, sockets, FIFOs, and some special files are sequential-only streams
- Common when a program designed for regular files receives a pipe via shell redirection
- Applications that check file size (fstat then lseek to end) fail on pipe input
- Some compression tools need to seek backward and cannot work with pipes
Common Causes
- Program using lseek() on stdin when input is piped (cat file | program)
- Application trying to read file size of a pipe or socket
- Compression/archive tool needing random access but receiving a stream
- Database trying to seek within a network socket connection
- Shell script using seek operations on a FIFO special file
Steps
- 1Use a temporary file instead of a pipe: command > /tmp/data && program /tmp/data
- 2Use process substitution: program <(command) — creates a regular file descriptor on some systems
- 3For input from pipe: buffer entire input to a temp file first, then process
- 4Check if the program supports reading from stdin without seeking (--stdin or - flag)
- 5Use named pipe with appropriate buffering: mkfifo /tmp/mypipe