-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23.c
More file actions
52 lines (45 loc) Β· 1.49 KB
/
23.c
File metadata and controls
52 lines (45 loc) Β· 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
============================================================================
Name : 23
Author : Piyush Singh
Description : Write a program to print the maximum number of files can be opened within a process and
size of a pipe (circular buffer).
Date: 25th Sep, 2025.
============================================================================
*/
// Program: Show max open files per process and pipe buffer size
#include <stdio.h> // For printf(), perror()
#include <stdlib.h> // For exit()
#include <unistd.h> // For pipe(), sysconf()
#include <sys/resource.h> // For getrlimit()
int main()
{
// Part 1: Max number of open files per process
struct rlimit limit;
if (getrlimit(RLIMIT_NOFILE, &limit) == 0)
printf("π’ Max open files per process: %llu\n", (unsigned long long)limit.rlim_cur);
else
perror("β getrlimit failed");
// Part 2: Pipe buffer size
int pipefd[2];
if (pipe(pipefd) == -1)
{
perror("β Pipe creation failed");
exit(1);
}
// Use fpathconf to query pipe buffer size
long pipe_size = fpathconf(pipefd[0], _PC_PIPE_BUF);
if (pipe_size != -1)
printf("π¦ Pipe buffer size (bytes): %ld\n", pipe_size);
else
perror("β fpathconf failed");
close(pipefd[0]);
close(pipefd[1]);
return 0;
}
/*
Output:
β°β ./23 ββ―
π’ Max open files per process: 256
π¦ Pipe buffer size (bytes): 512
*/