C is a general-purpose computer programming language used for operating systems, games and other high performance work and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the Unix operating system.

learn more… | top users | synonyms

140
votes
4answers
51k views

Why is FreeBSD deprecating GCC in favor of Clang/LLVM?

So I was surfing the net and stumbled upon this article. It basically states that FreeBSD, starting from Version 10 and above will deprecate GCC in favor of Clang/LLVM. From what I have seen around ...
16
votes
3answers
10k views

What are pseudo terminals (pty/tty)?

This might be really basic question but I want to understand it thoroughly. What is a pseudo terminal? (tty/pty) Why do we need them? How they got introduced and what was the need for it? Are they ...
12
votes
2answers
2k views

Why can't I run this C program?

I'm trying to run my first "process" program, but I get the following error : ./fork.c: line 4: syntax error near unexpected token `(' ./fork.c: line 4: `int main()' I'm pretty sure that the code ...
11
votes
4answers
4k views

After fork(), where does the child begin its execution?

I'm trying to learn UNIX programming and came across a question regarding fork(). I understand that fork() creates an identical process of the currently running process, but where does it start? For ...
10
votes
6answers
1k views

What C library version does my system use?

How can I tell for sure what userland C library my system uses? Possible reasons to need this information include: There's a gigantic source package I am considering downloading which I'm sure will ...
10
votes
2answers
213 views

Is there a way to mirror USB outputs?

I'm currently writing a program for a project. It is for a braille reading system where I have a braille display connected via USB that is controlled by a program called brltty. One of the ...
9
votes
5answers
1k views

What is meant by “a system call” if not the implementation in the programing language?

I would like to understand the term "system call". I am familiar that system calls are used to get kernel services from a userspace application. The part i need clarification with is the difference ...
9
votes
1answer
3k views

While there is C++ why most of Linux programs are written in C?

Why most of linux programs are written in C? Why they are not written with C++ which is newer than C?
8
votes
10answers
1k views

Development environment for C

Looking for ideas on setting up a convenient and productive development environment for C development. I found C editing with Vim very helpful but I would like to get a wider sampling of suggestions.
8
votes
4answers
2k views

Why should a child of a vfork or fork call _exit() instead of exit()?

From the man page of vfork(): vfork() differs from fork() in that the parent is suspended until the child makes a call to execve(2) or _exit(2). The child shares all memory with its ...
8
votes
3answers
6k views

Man pages for standard C and C++ libraries on Fedora 14

How do I install them? At present, man fopen gives me No manual entry for fopen. I have the compilers installed and have verified that things do build without problems. Update: This is what I got ...
7
votes
7answers
1k views

Possible to find out the sizes of data types (int, float, double, …) on a system, without writing a C program?

Is it possible to find out the sizes of data types (int, float, double, ...) on a Linux system, without writing a C program? Would the results for C same as for C++, and other programming languages ...
7
votes
2answers
5k views

How to compile a c program without leaving the editor? [duplicate]

I am using vim editor on Linux mint. I want to know if there is any way to compile c program without leaving the editor.
6
votes
5answers
3k views

Develop / Debug C / C++ on Ubuntu?

What's the best IDE for developing C / C++ on Ubuntu? I tried installing Eclipse but it seems like I need the eclipse-cdt package also. The problem is there is no such package, at least for Lucid. ...
6
votes
4answers
10k views

make a log file

Is there any way to make a log file for maintaining some data in /var/log/ with the help of some library function or system call in c language in linux. And I also want to know the standards that we ...
6
votes
1answer
311 views

Why would one want to compile multiple .cpp files to the same executable?

Why would you do g++ -Wall -I/usr/local/include/thrift *.cpp -lthrift -o something instead of: g++ -Wall -I/usr/local/include/thrift -c Something.cpp -o something.o g++ -Wall ...
6
votes
2answers
182 views

System programming: How to gather info?

According to this question, a good way to learn system programming would be to implement the existing tools. I decided to try to rewrite ls and ps. My question is how would one proceed to get ...
6
votes
2answers
3k views

Get CPU utilization stats from C program

I want to read the CPU utilization stats from a C program, I am interested in the percentage of use of CPU, steal time etc. These stats are shown in the 3rd row from the top command. I tried to parse ...
6
votes
1answer
246 views

Executing a shared library

Some shared libraries provide an output when called from the command line as if they were executables. For example: $ /lib/libc.so.6 GNU C Library stable release version 2.13, by Roland McGrath et ...
6
votes
2answers
3k views

How can I find a memory leak of a running process?

Is there a way, I can find the memory leak of a running process? I can use Valgrind for finding memory leaks before the start of a process. I can use GDB to attach it to a running process. How could I ...
5
votes
4answers
497 views

chdir(<directory>) doesn't change directory after exiting to shell

I wanted to make a simple C program to change to my project directory. Its content is following: #include <unistd.h> int main(){ chdir("/home/enedil/projects/algo"); return 0; } I ...
5
votes
2answers
340 views

What would I get when sudo a kernel-destructive program?

It suddenly comes to me how easy it will be for a sudoer to crash the kernel, so I tried something like this: #include<stdio.h> int main(){ printf("hello world"); int a; ...
5
votes
1answer
24k views

gcc can't link to pthread?

I have recently installed XUbuntu 11.10 64bit, but I am having problem compiling the most simple pthread example. Here is the code pthread_simple.c: #include <stdio.h> #include ...
5
votes
4answers
916 views

Does optimizing for size reduce runtime memory usage as well as binary size?

Does optimizing for size with gcc -Os only reduce the binary size of a program, or does it reduce its runtime memory usage as well? I know what exactly the results are depend on the specific code, but ...
5
votes
3answers
4k views

How do I kill all a user's processes using their UID

I want to kill all running processes of a particular user from either a shell script or native code on a linux system. Do I have to read the /proc directory and look for these? Any ideas? Is there a ...
5
votes
2answers
3k views

How to run a C program as a daemon?

I have a C program which I want to run as a daemon. How do I install it so it will run as a daemon on CentOS? Someone said to use @reboot, and some said to put it in /etc/rc.d/rc.local. Which is the ...
5
votes
1answer
3k views

How can i know which unistd.h file is loaded?

I have several unistd.h files in my Ubuntu Linux. I've one on: /usr/include/asm/unistd.h This file has this directives: # ifdef __i386__ # include "unistd_32.h" # else # include "unistd_64.h" # ...
5
votes
4answers
1k views

Error while loading shared libraries

My project tree looks something like that: src/ include/ Makefile lib/ lib/3rdparylib/ I didn't code 3rdpartylib, but decided to embed its source code in my project packaging. I compile the ...
5
votes
1answer
456 views

command substitution handling in fish vs. other shells (sh, bash, zsh)

The program mc (Midnight Commander) is not intended to be used for command substitution, but I would like to know why different shells behave differently when this program (and it seems like other ...
5
votes
1answer
1k views

How can I get a static C compiler?

I'm playing around with chroot environments, and I'd like to have a portable C compiler so that I can easily set up some basic build-tools in each environment without having to move too many libraries ...
4
votes
4answers
642 views

Is it possible to make multi-level directory? [duplicate]

Using mkdir() (the C function) I can create a 1-level directory, if I want to create multi_level directory like: folder/subfolder/subsubfolder is it possible? if so, how?
4
votes
3answers
305 views

“which” equivalent for shared libraries

I am looking for a utility that would behave in the same way as which, but to look up shared libraries (*.so) in the directories defined in $LD_LIBRARY_PATH?
4
votes
2answers
3k views

How to find the header file where a c function is defined?

Is there an easy way to find out which header file a C function declaration is in? cding into /usr/include and running (grep -E 'system.*\(' *.h -R) works with some trial and error, but isn't there an ...
4
votes
3answers
366 views

Are there “esoteric” (weird) but standards-compliant C compilers or runtimes?

As we know, the C standard does not specify a lot of details of the implementation, for example value of NULL pointer, order of bits and bytes (endiannes), alignment in structs and of stack ...
4
votes
1answer
174 views

Effect of static and dynamic linking on start address

I have a simple C program. I run: $ gcc Q1.c -Wall -save-temps -o Q1 Then I inspect the executable generated: $ objdump -f Q1 Q1: file format elf32-i386 architecture: i386, flags 0x00000112: ...
4
votes
3answers
286 views

Why is there a type for process ids (pid_t), but not for file descriptors (fd)?

I see that pid_t is typedef'd in unistd.h, and file descriptors are defined to be int in fcntl.h. But since they are used in similar ways, wouldn't it make sense to have a typedef for file ...
4
votes
1answer
65 views

How to compile programs on Linux systems when I don't have sudo privileges to install the dev dependencies [duplicate]

How should I go about compiling programs that depend on libraries whose development packages (headers and such) aren't pre-installed on the system when I don't have sudo access? In this particular ...
4
votes
2answers
1k views

Implementing a Unix shell in C: Logging

I am currently working on implementing my own UNIX shell in C. The basis of the shell is working, you could find the source code here. Right now my next task is to implement a logging feature for the ...
4
votes
1answer
1k views

Sparse files/file holes and unexpected block size

For my own learning, I've been playing around with creating files with file holes. I created a util that simply reads from stdin and writes to a file, but before writing to the file, it uses lseek to ...
4
votes
1answer
2k views

Writing to stdout except for output redirection C

I have to make a simple app for school. I have to write arguments one per line on the terminal, and return on stdout the user choices. For example, I write cat my_app main.c main.h, if the user ...
4
votes
1answer
1k views

Does free() unmap the memory of a process?

I am running a C program on Linux 2.6.16 kernel. I do not think there are memory leaks in my program however the memory consumption for the program remains stable after certain operations and does not ...
4
votes
2answers
5k views

“sys/ioctl.h” header in linux

I am on Linux 2.6.32-26-generic When I look in to the linux source code for "ioctl.h" hearer file, I could see many variants. (for different platforms, I guess). i.e. ./fs/ocfs2/ioctl.h ...
4
votes
1answer
100 views

Portions of the file Header

I was working through my C programs, I am new to Linux/UNIX development and was having a look around. I created a simple C program of Hello world and was inspecting the compilation process. I tried ...
4
votes
1answer
1k views

How to create a fake device file that accepts input from a C program?

I want to create a C program that accepts input from a joypad (/dev/input/js0), processes it, and then sends it to a fake device file (character or block) labeled as a keyboard (oh, and what is the ...
3
votes
2answers
595 views

Why does Linux have a C compiler by default?

Why does a Linux distribution have gcc installed in advance? Is it because most of the applications in linux are written in C? What would happen if the gcc directory is deleted?
3
votes
3answers
481 views

default wordsize in UNIX/Linux

I was inspecting the preprocessed output of my C program and happened to look at the header file wordsize.h It is located in /usr/include/i386-linux-gnu/bits/wordsize.h the file contains only one ...
3
votes
2answers
436 views

How to adjust time command to measure a program elapsed time

I'm trying to get the time that my program takes to finish (aka elapsed time) so I'm using the common time. What I get by doing this is 3 measurements: user, system and total. This is fine but I ...
3
votes
2answers
99 views

How to write software to compile with external libraries?

I want to code open source software with dependencies. I have skills in C/C++ and a minimum makefile knowledge. But im curious about coding this like ./configure && make stuff and how to ...
3
votes
1answer
135 views

In Emacs, editing C, sort-fields not working, or stating sole completion. Why?

In Emacs, editing C, and trying to execute sort-fields doesn't seem to be working. I enter M-x sort-fields after highlighting a region. At one point it was letting me pass a field number, but then ...
3
votes
2answers
335 views

Is there a glibc API that can find the default handing application for a MIME type on linux?

I want to find the default handling application in my C program. Is there a C API with same functionality as xdg-mime query default mime-type on Linux?