Home > Programming > Listing out the sysconf() values

Listing out the sysconf() values

Ever wondered how you could list out the defined sysconf() arguments constants and the sysconf() values for them. Well here is a simple bash script that worked for me:

#!/bin/bash

rm -f test.c

echo “#include <unistd.h>” >> test.c
echo “#include <stdio.h>” >> test.c
echo “main()” >> test.c
echo “{” >> test.c

for x in `echo “#include <unistd.h>” | cpp | grep _SC_ | cut -d ‘,’ -f 1 | awk ‘{print $1}’`
do
echo “printf(\”$x : %d\\n\”, sysconf($x));” >> test.c
done

echo “}” >> test.c

gcc test.c -o test

./test

rm -f test{,.c}

Categories: Programming
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.