Skip to content
Advertisement

Tag: c++

Best way to implement busy loop?

What is the best way to implement the busy loop ? correct me if i am wrong ? Answer To do an infinite wait, for a signal (what else) there is the pause() system call. You’ll have to put it in a loop, as it returns (always with -1 and errno set to EINTR) every time a signal is delivered:

Check whether a path is absolute or relative

How do you check whether a path is absolute or relative, using C on Linux? Answer On Unix like systems (incl. Linux, macOS) If it starts with a slash it’s absolute, otherwise it’s relative. That is because everything is part of a single tree starting at the root (/) and file systems are mounted somewhere in this tree. On Windows

Compiling C Program on OS X to Run on Linux

I have a pretty simple C program that does some cryptographic calculations using only standard library functions. I will be running the program on Ubuntu (10.04, 32 bit) and compiled it on OS X 10.6 using cc with the -m32 flag. When I tried to run it on Ubuntu I got the error message “cannot execute binary file.” When I

What does the brk() system call do?

According to Linux programmers manual: brk() and sbrk() change the location of the program break, which defines the end of the process’s data segment. What does the data segment mean over here? Is it just the data segment or data, BSS, and heap combined? According to wiki Data segment: Sometimes the data, BSS, and heap areas are collectively referred to

Changing working directories in Linux shell in a C program

My goal is to write a C program that is like a basic shell for Linux. I have everything working except changing working directories. I have tried the system() for input strings for cd and nothing happened. I also tried chdir(“tokened string”) and also no luck. Anyone have any ideas? This is part of my code: Is it possible to

Determine programmatically if a program is running

In C, how can I find out programmatically if a process is already running on Linux/Ubuntu to avoid having it start twice? I’m looking for something similar to pidof. Answer You can walk the pid entries in /proc and check for your process in either the cmdline file or perform a readlink on the exe link (The following uses the

Getting cannot allocate memory error

I am getting this error in my program… ulimit -a gives the output: The amount of memory I’m trying to protect is 60 MB. Can someone tell me what is the problem and how it can be solved? Answer Given the error message, you probably got an ENOMEM error, and looking at the error code, this does not necessarily mean

Advertisement