Error Codes Wiki

Linux ESPIPE (errno 29) — Illegal Seek on Pipe/Socket

Informationalerrno

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

  1. 1Use a temporary file instead of a pipe: command > /tmp/data && program /tmp/data
  2. 2Use process substitution: program <(command) — creates a regular file descriptor on some systems
  3. 3For input from pipe: buffer entire input to a temp file first, then process
  4. 4Check if the program supports reading from stdin without seeking (--stdin or - flag)
  5. 5Use named pipe with appropriate buffering: mkfifo /tmp/mypipe

Tags

linuxespipeerrno-29seekpipe

More in Errno

Frequently Asked Questions

Pipes are one-directional streams with no random access. Data flows from writer to reader sequentially — there is nothing to seek to.