posix

Programming with C/C++ in Ubuntu linux

How to display beginning sector of each partition in ubuntu ?like in windows there is an API to call disk structure in c/C++ .. any suggestions will be help full. ...

Detect if gdb is running

Hello! I'd like to detect from an application wether gdb is running. The standard way would be the following: if (ptrace(PTRACE_TRACEME, 0, NULL, 0) == -1) printf("traced!\n"); In this case ptrace returns an error if the current process is traced (i.e. running it with gdb or attaching to it). But there is a serious problem with th...

determine file permissions for the current user

I am looking for a way to determine file permissions for the current user (i.e. the process's UID) on POSIX-compliant systems. I don't want to try opening the file - that could get messy with directories and all kinds of special files. I am compiling a directory listing of a specified directory, and for each file, reporting a bunch of t...

Doubt in malloc. C (Linux)

In the following code,what is the meaning of buf = malloc(n * sizeof(char)); is n*sizeof(char) necessary,if yes.. please elaborate. int n; char* buf; fstat(fd, &fs); n = fs.st_size; buf = malloc(n * sizeof(char)); EDIT1 And What if I write (n*sizeof(double)) ...

Can't handle Floating Point Exception (FPE) for the second time.

I have written a program that handles signal for Floating point exception and I am using Ubuntu 10.4. Here's my source code : #include <stdio.h> #include <stdlib.h> #include <signal.h> #include <setjmp.h> sigjmp_buf mark; void GeneralHandler(int signo) { switch(signo) { case SIGFPE: printf("\nERROR : Inva...

Multithread and SMP Linux

The Linux Kernel is said to be SMP. It is said that processes and kernel threads shall be distributed across processors. Does all Linux distribution like fedora13, ubuntu 10.04 Lucid by default enable SMP Linux? On an SMP Linux, which is better to follow- a) multi-process approach versus b) multi-threading approach Does pthrea...

Exit functions in C

What is the difference between exit(), _exit() and _Exit() in C? How do I decide which to use? On bash, man 2 exit gave me the page _EXIT(2), whereas man 3 exit gave the page EXIT(3). ...

Implementing EINVAL, EPERM, ESRCH in Kill()

I am trying to implement EINVAL, EPERM, ESRCH in my program. ERRORS EINVAL An invalid signal was specified. EPERM The process does not have permission to send the signal to any of the target processes. ESRCH The pid or process group does not exist. Here's my source code : #include <stdio.h> #include <sys/types.h> #inc...

Returning Exit code from child

I'm trying to return an integer value from a child process. However, if I use exit(1) i get 256 as the output. exit(-1) gives 65280. Is there a way I can get the actual int value that I send from the child process? if(!(pid=fork())) { exit(1); } waitpid(pid,&status,0); printf("%d",status); Edit: Using exit(-1) (which is what I a...

Partial unmap of Win32 memory-mapped file

I have some code (which I cannot change) that I need to get working in a native Win32 environment. This code calls mmap() and munmap(), so I have created those functions using CreateFileMapping(), MapViewOfFile(), etc., to accomplish the same thing. Initially this works fine, and the code is able to access files as expected. Unfortuna...

What does waitpid() do?

What is the use of waitpid()? ...

Is there any possible way to change a memory location to a shared memory in C?

In c you can do shmid = shmget(SHMEM_KEY, sizeof(int*) * n , SHEMEM_MODE | IPC_CREAT); int* shmem = shmat(shmid, NULL, 0); to assign first given free memory space as a shared memory. Is there any way to assigne current memory space as a shared memory? ...

Display all process using a posix function.

I am trying to display currently running process in Ubuntu. Right now I am using system() function to print running process in the terminal. Code: system("ps -A"); This function displays all running process in the terminal. But I want to this functionality using a POSIX function. I am not looking for a ready made code. Can some on...

How do you get info for an arbitrary time zone in Linux / posix?

Ideally, what I'd like to be able to do is take the name of a time zone and call a function to ask for its corresponding time zone info (offset from UTC, DST offset, dates for DST switch, etc.) in Linux. However, I can't find any way to do this. The information exists in /usr/share/zoneinfo/ in the various binary files there, but I don't...

How to pass multiple parameters to a thread function.

I have created a function for a thread, but I want to pass multiple parameters to the function. Here's my source code : #include "work.h" #include <stdio.h> #include <unistd.h> #include <pthread.h> // compile with -lpthread int count = 20; void* ChildProc(void* arg) { int i; for(i = 1; i <= count; i++) { pr...

basename_r/dirname_r in Linux

Some POSIX functions are not threadsafe. Examples are dirname and pathname. The dirname() function need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe. On some platforms there are reentrant versions of dirname and pathname: dirname_r and pathname_r. As far as I found out there ar...

can we use POSIX sockets in iPhone

Can i use POSIX sockets in iPhone OS? ...

Why is there no uncatchable coredump signal?

I recently came across an app that froze in a SIGABRT handler with no other signal registered to immediately core dump. Until we standardize leaving one of SIGSTOP, SIGABRT, SIGTRAP, etc., alone, we'll just use gcore and SIGKILL, but given that broken handling was the issue, I wondered why there isn't along with SIGSTOP and SIGKILL a st...

Pipes to C++ Streams

is it possible to turn pipes genereated via pipe() on a POSIX-system into std::istreams and std::ostreams? if yes, how? i would prefer to use << and >> instead of read() and write() thanks in advance ...

Do POSIX lfind()/lsearch() perform better than looping manually?

Do lfind/lsearch perform better than a typical looping solution that checks each item until it matches? Is there any special sauce/reason that these functions exist? ...