system-calls

Recovery from optical media ignoring read errors

I have backups of files archived in optical media (CDs and DVDs). These all have par2 recovery files, stored on separate media. Even in cases where there are no par2 files, minor errors when reading on one optical drive can be read fine on another drive. The thing is, when reading faulty media, the read time is very, very long, because ...

Redundant Linux Kernel System Calls

I'm currently working on a project that hooks into various system calls and writes things to a log, depending on which one was called. So, for example, when I change the permissions of a file, I write a little entry to a log file that tracks the old permission and new permission. However, I'm having some trouble pinning down exactly wh...

Is it bad practice to use the system() function when library functions could be used instead? Why?

Say there is some functionality needed for an application under development which could be achieved by making a system call to either a command line program or utilizing a library. Assuming efficiency is not an issue, is it bad practice to simply make a system call to a program instead of utilizing a library? What are the disadvantages o...

Common Lisp GUI Programming With System Calls

Can anyone tell me about using (Steel Bank) Common Lisp for writing GUIs via system calls? I know there are some libraries out there but this is a language learning exercise, so I want to do it myself. I'm developing on Kubuntu 8.10 and SBCL 1.0.18. Thanks. ...

How to control which core a process runs on?

I can understand how one can write a program that uses multiple processes or threads: fork() a new process and use IPC, or create multiple threads and use those sorts of communication mechanisms. I also understand context switching. That is, with only once CPU, the operating system schedules time for each process (and there are tons of ...

System calls from .NET to mono

I'm trying to make an external system call using mono. I'd like to know if it's possible to emulate something like the example below (Of course I'm looking for cross platform support). public static int ExecuteExternalApp() { int ExitCode = -1; Process Process = new Process(); ; ...

How to create a linux equivalent "nl" command using system calls in C?

I have an exercise to do where I need to code in C, commands equivalent to cat and nl using only system calls. The system calls given to us are open(), close(), read() and write(). I've already done the "cat" equivalent and it seems to be running fine, now I need to do the "nl" one but I'm having trouble with how am I going to write lin...

mmap() internals

It's widely known that the most significant mmap() feature is that file mapping is shared between many processes. But it's not less widely known that every process has its own address space. The question is where are memmapped files (more specifically, its data) truly kept, and how processes can get access to this memory? I mean not *(p...

Why is my "cat" function with system calls slower compared to Linux's "cat"?

I've done this function in C using system calls (open, read and write) to simulate the "cat" function in Linux systems and it's slower than the real one... I'm using the same buffer size as the real "cat" and using "strace" I think it's making the same amount of system calls. But the output from my "cat" is a little bit slower than the ...

How to use system calls like fork, wait and exit in C to solve my problem?

I have this problem to solve that I have no idea how to do it because there's only a few system calls we can use to solve it and I don't see how they are helpful for the situation. The Exercise: I have matrix with size [10][1000000] with integers and for each line I create a new process with fork(). The idea of each process is to go thr...

Any benefit in using WEXITSTATUS macro in C over division by 256 on exit() status?

I was doing an exercise for university where I had to return a value with exit, that value was actually a count of something. This could be above 255 (which exit() can't handle) but the teacher suggested to use test data where the count could never go above that value. After all this, I needed to handle this count value, the exit status...

Too many calls to mprotect

I am working on a parallel app (C, pthread). I traced the system calls because at some point I have bad parallel performances. My traces shown that my program calls mprotect() many many times ... enough to significantly slow down my program. I do allocate a lot of memory (with malloc()) but there is only a reasonable number of calls to ...

Spurious readiness notification for Select System call

On http://linux.die.net/man/2/select, under BUGS section it is mentioned that the select system call may sometimes spuriously set the FD ready and the subsequent read call will return 0. The text describes one such example (wrong checksum) but I am assuming there would be other reasons too (otherwise they would have fixed this). Any id...

How to ignore arrow keys in C reading from stdin?

I'm reading from the standard input using the read() system call but there's a tiny thing that bothers me. I can't use the arrow keys... What I really wanted to do was to use arrow keys to go back and forth within the typed text but I think that's not that easy... So, what I at least want to do, is to ignore them. Right now, pressing an...

Are there any standard input/ouput macros for read/write system calls in C?

All my searches returned nothing and I find it odd that there aren't any macros to use as file descriptors for read/write system calls for standard input and output instead of a 0 (stdout) and a 1 (stdin). Am I missing them or they really don't exist? ...

How are sbrk/brk implemented in Linux?

I was thinking about how the Linux kernel implements system calls and I was wondering if someone could give me a high level view of how sbrk/brk work? I've reviewed the kernel code, but there is just so much of it and I don't understand it. I was hoping for a summary from someone? ...

Programatically getting UID and GID from username in Unix?

I'm trying to use setuid() and setgid() to set the respective id's of a program to drop privileges down from root, but to use them I need to know the uid and gid of the user I want to change to. Is there a system call to do this? I don't want to hardcode it or parse from /etc/passwd . Also I'd like to do this programatically rather tha...

unix system call monitor

how to monitor system calls for a process? ...

How can I make system calls invoke my SIGSEGV handler when given protected memory?

I'm working on a memory tracking library where we use mprotect to remove access to most of a program's memory and a SIGSEGV handler to restore access to individual pages as the program touches them. This works great most of the time. My problem is that when the program invokes a system call (say read) with memory that my library has mar...

Does getpwnam respect /etc/nsswitch.conf?

Does getpwnam respect /etc/nsswitch.conf? The manpage for getpwnam states The getpwnam() function returns a pointer to a structure containing the broken-out fields of the record in the password database (e.g., the local password file /etc/passwd, NIS, and LDAP) that matches the username name. This leads me t...