Questions tagged [c]

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.

832 questions
252
votes
4 answers

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 the net so far, Clang/LLVM is a fairly ambitious…
NlightNFotis
  • 7,525
  • 7
  • 32
  • 38
118
votes
11 answers

Why does argv include the program name?

Typical Unix/Linux programs accept the command line inputs as an argument count (int argc) and an argument vector (char *argv[]). The first element of argv is the program name - followed by the actual arguments. Why is the program name passed to…
Shrikant Giridhar
  • 1,267
  • 2
  • 11
  • 13
101
votes
6 answers

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 dynamic mapping of the pids under UIDs in Linux?…
user489152
  • 1,113
  • 2
  • 9
  • 6
86
votes
7 answers

Are threads implemented as processes on Linux?

I'm going through this book, Advanced Linux Programming by Mark Mitchell, Jeffrey Oldham, and Alex Samuel. It's from 2001, so a bit old. But I find it quite good anyhow. However, I got to a point when it diverges from what my Linux produces in the…
user147505
60
votes
4 answers

Why does a program with fork() sometimes print its output multiple times?

In Program 1 Hello world gets printed just once, but when I remove \n and run it (Program 2), the output gets printed 8 times. Can someone please explain me the significance of \n here and how it affects the fork()? Program 1 #include…
lmaololrofl
  • 653
  • 1
  • 5
  • 6
51
votes
6 answers

How to dump a binary file as a C/C++ string literal?

I have a binary file I would like to include in my C source code (temporarily, for testing purposes) so I would like to obtain the file contents as a C string, something like this: \x01\x02\x03\x04 Is this possible, perhaps by using the od or…
Malvineous
  • 6,524
  • 5
  • 52
  • 76
51
votes
6 answers

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 do proper checks and lists a mininum library…
goldilocks
  • 86,451
  • 30
  • 200
  • 258
36
votes
2 answers

Default stack size for pthreads

As I understand, the default stack size for a pthread on Linux is 16K. I am getting strange results on my 64-bit Ubuntu install. $ ulimit -s 8192 Also: pthread_attr_init(&attr); pthread_attr_getstacksize(&attr, &stacksize); printf("Thread stack…
Kamath
  • 595
  • 2
  • 6
  • 7
34
votes
3 answers

Why are most Linux programs written in C?

Why are most Linux programs written in C? Why are they not written with C++, which is newer?
hpn
  • 1,431
  • 7
  • 18
  • 21
33
votes
3 answers

Do C compilers discard unused functions when statically linking to .a file?

Say I have a C program main.c that statically links to libmine.a. Statically linking to a library causes library functions to be embedded into the main executable at compile time. If libmine.a were to feature functions that weren't used by main.c,…
Izzo
  • 999
  • 1
  • 8
  • 15
33
votes
5 answers

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 debug a memory leaks of a running process?
howtechstuffworks
  • 439
  • 1
  • 5
  • 5
32
votes
3 answers

How does copy-on-write in fork() handle multiple fork?

According to Wikipedia (which could be wrong) When a fork() system call is issued, a copy of all the pages corresponding to the parent process is created, loaded into a separate memory location by the OS for the child process. But this is not…
ssgao
  • 431
  • 1
  • 4
  • 5
26
votes
4 answers

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 example, if I have code int main (int argc, char…
thomas1234
26
votes
7 answers

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 in the same Linux system?
Tim
  • 98,580
  • 191
  • 570
  • 977
25
votes
2 answers

Does POSIX guarantee the paths to any standard utilities?

From C, what's the easiest way to run a standard utility (e.g., ps) and no other? Does POSIX guarantee that, for example, a standard ps is in /bin/ps or should I reset the PATH environment variable to what I get with confstr(_CS_PATH, pathbuf, n);…
Petr Skocik
  • 28,176
  • 14
  • 81
  • 141
1
2 3
55 56