system-calls

How to write text containing newline given as command line arguments in C?

孤街浪徒 提交于 2021-02-10 15:46:26
问题 I want to create a text file with mulitple lines using system calls in C and populate it with the text provided as command line arguments. This is what I wrote: #include <stdio.h> #include <fcntl.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #define MAX_SZ 1024 int main(int argc, char *argv[]) { if (argc != 3) { printf("Invalid Number of arguments\n"); printf("USAGE: ./a.out file_name \"msg\"\n"); } else { int fd_creat, fd_open, fd_write; char file_name[MAX_SZ]; char *msg =

Assembly clone syscall thread function not called

醉酒当歌 提交于 2021-02-10 14:47:00
问题 Im trying to create a thread using 'clone' syscall ... i searched toooooooo much ! for example, link1 link2 and now this is my source code in assembly for linux x64: FORMAT ELF64 EXECUTABLE ENTRY thread_linux_x64 THREAD_MEM_SIZE = 1024 define PROT_READ 0x1 define PROT_WRITE 0x2 define PROT_EXEC 0x4 define MAP_PRIVATE 0x02 define MAP_ANONYMOUS 0x20 define CLONE_VM 0x00000100 define CLONE_FS 0x00000200 define CLONE_FILES 0x00000400 define CLONE_SIGHAND 0x00000800 define CLONE_PARENT 0x00008000

R supress console output of a system or shell command

二次信任 提交于 2021-02-09 08:16:19
问题 I have this windows-batchfile which I'm calling from R using the shell() command. This batchfile does some calculations and writes them on the disk but also on the screen. I'm interested in the disk-output, only. I cannot change the batchfile. The batchfile might be something silly like: @echo off echo 1 + 2 @echo 1 + 2 > C:\TEMP\batchoutput.txt exit I tried shell("batchfile.bat", invisible = TRUE) 1 + 2 shell("batchfile.bat", show.output.on.console = FALSE) Error in system(cmd, intern =

How can I make Linux system calls from a C/C++ application, without using assembly, and in a cpu-independent manner? [closed]

孤人 提交于 2021-02-08 10:30:52
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question I am looking to write a program that will need to do low level work with processes (ie. using the fork system call, among others). This program is to be written in C++ and is to run only on Linux. Ideally, it will be portable across CPU architectures (ie. x86, x86

How can I make Linux system calls from a C/C++ application, without using assembly, and in a cpu-independent manner? [closed]

有些话、适合烂在心里 提交于 2021-02-08 10:23:08
问题 Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question I am looking to write a program that will need to do low level work with processes (ie. using the fork system call, among others). This program is to be written in C++ and is to run only on Linux. Ideally, it will be portable across CPU architectures (ie. x86, x86

Is mode switch occur switching from user thread to kernel thread?

寵の児 提交于 2021-02-08 06:14:15
问题 I'm confused of user/kernel thread and mode/context switch (Platform: Linux) I have two linked questions. (1) Is the below sentence right? If I make a system call, then mode switch (user mode to kernel mode) will occur and eventually switching from user thread to kernel thread happens. Since system call can only be executed in kernel thread, I think mode switch must occur the switching from the user thread to kernel thread. (2) Then, what we call the overhead of mode switching is that

Is mode switch occur switching from user thread to kernel thread?

五迷三道 提交于 2021-02-08 06:09:21
问题 I'm confused of user/kernel thread and mode/context switch (Platform: Linux) I have two linked questions. (1) Is the below sentence right? If I make a system call, then mode switch (user mode to kernel mode) will occur and eventually switching from user thread to kernel thread happens. Since system call can only be executed in kernel thread, I think mode switch must occur the switching from the user thread to kernel thread. (2) Then, what we call the overhead of mode switching is that

Is mode switch occur switching from user thread to kernel thread?

一笑奈何 提交于 2021-02-08 06:07:51
问题 I'm confused of user/kernel thread and mode/context switch (Platform: Linux) I have two linked questions. (1) Is the below sentence right? If I make a system call, then mode switch (user mode to kernel mode) will occur and eventually switching from user thread to kernel thread happens. Since system call can only be executed in kernel thread, I think mode switch must occur the switching from the user thread to kernel thread. (2) Then, what we call the overhead of mode switching is that

Is mode switch occur switching from user thread to kernel thread?

核能气质少年 提交于 2021-02-08 06:07:11
问题 I'm confused of user/kernel thread and mode/context switch (Platform: Linux) I have two linked questions. (1) Is the below sentence right? If I make a system call, then mode switch (user mode to kernel mode) will occur and eventually switching from user thread to kernel thread happens. Since system call can only be executed in kernel thread, I think mode switch must occur the switching from the user thread to kernel thread. (2) Then, what we call the overhead of mode switching is that

finding the username in a linux system call

吃可爱长大的小学妹 提交于 2021-02-04 19:22:34
问题 I have added a system call to Linux kernel that looks like this: #include <linux/kernel.h> #include <linux/sched.h> #include <linux/list.h> #include <linux/cred.h> #include <asm/uaccess.h> asmlinkage int sys_os_pid_to_uid(int pid, int* puid) { struct task_struct* task; rcu_read_lock(); for_each_process(task) { if (task->pid == (pid_t) pid) { copy_to_user(puid, &(task->cred->uid.val), sizeof(task->cred->uid.val)); } } rcu_read_unlock(); return 0; } It gets a process ID ( pid ) and determines