FAQ Database Discussion Community


Write kernel system call that prints human readable time

c,linux,linux-kernel,kernel,system-calls
I'm trying to print the time within my own custom system call in a human readable format (Jan 29 2015 05:53:12 for example, though any order is fine). I'm using code I know works in a standard C program because I've used it before, but for some reason it doesn't...

system call hardware performance counters ubuntu

performance,ubuntu,operating-system,system-calls,perf
I am working on a project and I would like to obtain the performance counters(cache, TLB, etc) values of a system call(eg: read()) before and after the execution of a file. I tried doing this using perf on Ubuntu but was not able to get any results. Is there a...

Concurrent program in C(sequential issue)

c,linux,concurrency,fork,system-calls
I am trying to find a way to make this algorithm run concurrent and be simultaneous. So far it has only 1 for-loop that reads each file and then makes a process for each file. I believe this algorithm runs sequentially which is not what I want... I thought about...

accessing errno.h in assembly language

assembly,error-handling,system-calls
I want to access errno present in errno.h in assembly language in order to handle errors of write function call. I found somewhere that make call to _error in assembly language for this purpose but it is throwing errors as : ExitNewShell.asm:71: error: symbol `_error' undefined ExitNewShell.asm:85: error: symbol `_error'...

system call in C library function

c,operating-system,system-calls
Since the system calls which any library function of C (say printf()) makes is OS dependant , does that imply that we have a different function printf() for different OS ?

Read and Write operations get bad fd and no such file

c,unix,system-calls
I have this C program. I have two processes, father and son, and use semaphores to make them synchronize one at time. The father has to write (n) numbers, ten in this case, always in the first byte of the opened file and the son has to read it. The...

rmdir (2) used for directory tree removal

filesystems,standards,system-calls,syscall,standards-compliance
If a particular filesystem supports cheap removal of whole directories (with everything inside), would it be acceptable by POSIX / Linux / de-facto standards to let rmdir syscall delete a directory successfully even if it was not empty? Manpage for rmdir(2) syscall specifies an error ENOTEMPTY can (or should?) be...

ret_from_syscall source code and when it is called

linux,linux-kernel,kernel,linux-device-driver,system-calls
In the below call trace we see function called ret_from_syscall. Which function is this ? When it will called during system call ? Where is the corresponding code for this ? May 7 16:40:34.322086 warn TCU-0 kernel: [cf83ddc0] [00009751] 0x9751 (unreliable) May 7 16:40:34.322086 warn TCU-0 kernel: [cf83ddd0] [c00469ac] do_syslog+0x198/0x424...

How to identify performance bottleneck in linux system call unshare(CLONE_NEWNET)

c,linux,performance,namespaces,system-calls
I have a linux application (written in C) which is constantly creating and deleting network-namespaces. Typically a create/delete cycle takes around 300ms. During performance investigations, I ran strace on the program to find out which system call was taking most time. From the strace output, it seems that very first...

Fortran OPEN-call differs on NFSv3 vs NFSv4

linux,fortran,system-calls,gfortran,nfs
I'm trying to understand the difference between why you can do an OPEN-call in fortran on NFSv3 in read-write mode on a file that you only have read-permissions on, while if you do the same thing on NFSv4 the OPEN-call will fail. Let me explain, below is a simple fortran-program...

Modifying a file using C System Calls

c,system-calls
I want to modify a specific byte in a file using C system calls. I have some knowledge about open() and read() and write() system calls. Say i want to modify 1024th byte in a file and file has 2048 bytes. So i can read out 1024 bytes to a...

Trouble Understanding Fork Logic

process,fork,system-calls
Can someone help me understand what is happening in this segment of code? I am having trouble understanding why the output is how it is. Output is: 0 1 2 3 4 3 2 1 0 int main() { int i; for (i = 0; i < 5 && !fork();...

does the mode bit change when initialising a variable?

operating-system,kernel,system-calls
So I know that a system call (e.g. open, close, read, write etc.) changes the mode bit twice - from user mode to kernel mode to serve the system call request and then back to user mode once it's done. But if we have for example int a = open("lol.txt",...

How can I increase the MAX_PATH_LENGTH in a freeBSD system?

linux,filesystems,freebsd,system-calls
I am writing a 'find' like utility to search some particular files in a freebsd based system. The stat() call in freeBSD 9 can accept paths with length 1024 chars, though linux supports upto 4K char paths. The system itself has a filesystem other than freeBSD's (its a commercial OS)...

Software interrupts on AVR

posix,interrupt,system-calls,avr,syscall
I understand that x86 machine code can make POSIX system calls using software interrupts (by entering a 32-bit value corresponding to a kernel function into the EAX register of the processor and then executing INT 0x80). I'm looking into designing a small Unix-like operating system for the AVR architecture for...

checking EOF on unix cp program

unix,operating-system,system-calls
I'm writing a unix cp program, but I'm unclear about checking for EOF. The code I have is: int main(int argc, const char * argv[]) { int in, out; char buf[BUFFER_SIZE]; if (argc != 3) cout << "Error: incorrect number of params" << endl; if ((in = open(argv[1], O_RDONLY, 0666))...

System call access in Assembly language

assembly,system-calls
I want make system call (on linux) in Assembly. I have problem with system call access. In C code I write: int r= syscall(SYS_access,"file", R_OK); if(r==0){ printf("Can read\n"); } This in C work, but I don't know how can handle with flags and check return. Here is my code: mov...

Why my implementation of sbrk system call does not work?

linux,malloc,system-calls,dynamic-memory-allocation,sbrk
I try to write a very simple os to better understand the basic principles. And I need to implement user-space malloc. So at first I want to implement and test it on my linux-machine. At first I have implemented the sbrk() function by the following way void* sbrk( int increment...

Linux x86 syscall 355 is run repeatedly on bootup and causes crash unless returns -ENOSYS

linux,linux-kernel,x86,system-calls,syscall
kernel version: 3.14.33 Before I added any system calls, the highest-numbered one for x86 (32 bit) was 352. I then added 353-357 by simply adding a row each to arch/x86/syscall/syscall_32.tbl and then using SYSCALL_DEFINEx as appropriate in kernel/*. The problem is with the syscall numbered 355. It is run repeatedly...

How to trace system calls in FreeBSD from source code?

freebsd,system-calls,syscall,truss
How to log system calls (the syscall number and the return value, for both int 0x80 and sysenter/syscall) on FreeBSD 10.1 x86_64 from source code? I know truss can do the work, but I need to log other information like the buffer of copyout during each system call. I tried...

System calls in GAS

assembly,system-calls,gas
I'm trying to create a folder in 64 bit GNU as like this: .global main .text main: movl $83, %edi # SYS_mkdir movl $folder, %esi # folder_name movl $0777, %edx # flags call syscall ret # exit folder: .string "folder" this code works, however I'd rather implement it using the...

C synchronize processes using signal

c,linux,signals,system-calls,forking
Okay so I am trying to teach myself on how to do signalling, and I came across a hiccup and I can't figure out what I'm doing wrong. What is going on right now is: it is executing the parent then goes to child and then back to parent.. It's...

Getting the value of a system call [duplicate]

ruby,system-calls
This question already has an answer here: Getting output of system() calls in Ruby 14 answers I'm trying to get a value from a system call in Ruby: distro = system('lsb_release -is') distver = system('lsb_release -rs | cut -c1-2') I thought the return from the lsb_release comes into the...

How does the Linux kernel “listen” to the C library?

c,linux-kernel,system-calls,userspace
I'm trying to build up a "big picture" of how things work in the Linux kernel and userspace, and I'm quite confused. I know that userspace make use of system calls to "talk" to the kernel, but I don't know how. I tried to read the C library and kernel...

For Linux, how can I kill all processes in a session (with same SID) using system calls?

c,linux,system-calls,kill,sessionid
I am trying to figure how to kill all processses in a session (with the same SID) using system calls with C. I am not interested in to just kill all with a specific PGID since not all processes I am interested about does not have the same PGID, but...

Brute force attack test on password for file

perl,passwords,combinations,system-calls,brute-force
I'm trying to create a brute force that will work on a specific files password. I'm not sure how to get this code to work. This is what I have so far. This code produces the correct possible combinations for the password but I am not sure how to implement...

Linux system call time() is returning ((time_t) -14) on error

c,linux,time,system-calls
The man page man 2 time says: SYNOPSIS #include <time.h> time_t time(time_t *t); RETURN VALUE On success, the value of time in seconds since the Epoch is returned. On error, ((time_t) -1) is returned, and errno is set appropriately. ERRORS EFAULT t points outside your accessible address space. I've got...

Open /var/log/syslog and reading data using poll(), but poll() always reading same data again

linux,system-calls,epoll
Test Environment: Ubuntu 12.04 Description: I did the below # `sudo truncate -s 0 /var/log/syslog` # logger "helloworld". # `cat /var/log/syslog/` May 21 11:02:10 setup-VirtualBox setup: `helloworld` May 21 11:05:01 setup-VirtualBox CRON[3056]: `(root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)` But if am reading data through below...

Make windbg or kd attached to lokal kernel behave like system wide strace

windows,debugging,system-calls,windb
I am completely newbie in this area so please bare with me. I am running Windows 7 on which I want to do kernel debugging and I do not want to mess with boot loader. So I've downloaded LiveKd as suggested here and make it run and seems it is...

using system call in Linux kernel file

linux-kernel,scheduling,scheduler,system-calls
I am implementing a custom process scheduler in Linux. And I want to use a system call to record my program so that I can debug easily. The file I write is source code : linux-x.x.x/kernel/sched_new_scheduler.c In sched_new_scheduler.c could I use syscall(the id of the system call, parameter); directly? It...

Simultaneous writing in a file using pipes in linux

c,linux,file,pipe,system-calls
I have a file names.txt Pop,Jack and a file surnames.txt Ioan,Gry. I need to obtain the following output, person.txt, Pop Ioan, Jack Gry. I must create two programs: First read from file names.txt and write in person.txt. Second read from surnames.txt and write in person.txt. I need to use pipes...

Sending an intent from c++ to java in Android 5.0.1_r1

java,android,c++,android-intent,system-calls
After going through several posts I figured out I could send the intent with the following line of code (second line used for debugging): int ret = system("am broadcast -a android.intent.action.MIKE_ACCESSED --user 0"); __android_log_print(ANDROID_LOG_DEBUG, "gxp18", "Shell command returned %i", ret); Unfortunately, this returns always (No matter what is the command...

Whether program is executed from command line or invoked through system call

linux,command-line,executable,invoke,system-calls
Platform is linux and the c code is compiled in gcc. Is it possible to know from inside the code of program whether its executable has been executed directly from command line or invoked through "system" call ? e.g test.exe can be directly run on command line as ./test.exe or...

Confusion on how to use select() in TCP

sockets,tcp,server,system-calls
In int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); readfds & writefds - Can they be used simuntanouesly? EX: If i have a read operation and a send operation one after the other Also, can anybody provide a good link or sample program? Is select(...) used...

how to transfer string(char*) in kernel into user process using copy_to_user

linux-kernel,kernel,system-calls
I'm making code to transfer string in kernel to usermode using systemcall and copy_to_user here is my code kernel #include<linux/kernel.h> #include<linux/syscalls.h> #include<linux/sched.h> #include<linux/slab.h> #include<linux/errno.h> asmlinkage int sys_getProcTagSysCall(pid_t pid, char **tag){ printk("getProcTag system call \n\n"); struct task_struct *task= (struct task_struct*) kmalloc(sizeof(struct task_struct),GFP_KERNEL); read_lock(&tasklist_lock); task = find_task_by_vpid(pid); if(task == NULL ) {...

Using Ruby to execute arbitrary system calls

ruby,puppet,system-calls,return-code
This problem is to get into an internship within a devops department: "Write a ruby library that executes arbitrary system calls (eg: “dmesg", "ping -c 1 www.google.com”) and provides separated output streams of stderr and stdout as well are providing the final return code of the process. Show your work...

Why do we need to call poll_wait in poll?

linux,linux-kernel,linux-device-driver,system-calls,epoll
In LDD3, i saw such codes static unsigned int scull_p_poll(struct file *filp, poll_table *wait) { struct scull_pipe *dev = filp->private_data; unsigned int mask = 0; /* * The buffer is circular; it is considered full * if "wp" is right behind "rp" and empty if the * two are equal....