Is there any way to know the directory where the program is originally spawned in C? I want my program to know where it is located in the computer. I already tried using _getcwd() in direct.h. I also tried getcwd() using unistd.h. But here's the…
I would like to use getpid function from headers sys/types.h, unistd.h (C style) when I am using -std=c++11 flag but after that I have :
"function getpid could not be resolved".
Is there is some kind of workaround or equivalent function?
@Edit:
I…
I've looked at many of the questions asked here before, and I've decided to go with unistd.h for getopt.
However I have a need that a certain option depends on a previous option, as in
exe -a a_opt -b b_bopt
where the -b will do b_opt/a_opt
So it…
I am writing on a shell and want to implement the signals SIGSTP and SIGINT.
When the user starts a new process and presses CTRL+C it should send a SIGINT to the process and when CTRL+Z is pressed the process should get the SIGSTP signal.
Here is…
I'm trying to compile a dependent libraries from the source code and I've got this error:
/Applications/Xcode.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS9.0.sdk/usr/include/unistd.h:446:8:
note: 'fork' has been…
This question was a part of my Mid-Sememter Exams, and its answer as given by the prof is quite absurd.
I just want to know what is correct answer.
CODE:
#include
// Other Libraries
void ChildProc()
{
sleep(10);
…
when i search for adding a system call, i get many articles but they seem to be for old versions, it also seems like a trivial process.
But the problem is, the directories that articles suggest does not hold for the version 2.6.31. does anyone know…
for example there are some macros in the unistd_64.h
...
#define __NR_semget 64
#define __NR_semop 65
#define __NR_semctl 66
#define __NR_shmdt 67
#define __NR_msgget 68
#define __NR_msgsnd 69
...
when I input a number
64
, it will…
The following C program attempts to fetch and print the host name of the current RHEL host. It throws a segmentation fault on this machine. As per the definition of gethostname I should be able to pass a char pointer, shouldn't I?
When I use a char…
EDIT: the warning in the first paragraph was due to me reading the old log from the compiler (before including unistd.h, sorry for the missconfusion, the second problem still resides)
I have a code that makes use of the c function unlink (declared…
One of the issues I've encountered whilst making a recursive directory lister is that a call after a directory check isn't invoked in the recursive function's stack.
void direct_crawl(int indent, char *cwd, STAT nstat)
{
int i, i_in, count;
…
My program is working almost as it should. The intended purpose is to read the file from the end and copy the contents to destination file. However what confuses me is the lseek() method more so how I should be setting the offset.
My src contents at…
I am using read() from unistd.h on a file descriptor. I need to read the first 4 bytes to an int variable and the rest to a unsigned char array.
So far, this does not work for getting the first 4 bytes:
unsigned int myInt = 0;
status = read (fd,…
I am using
unistd.h
sys/stat.h
and what is interesting is that st_size is bigger than the value returned after read()?
st.st_size returns 644 - read() returns 606,
Any thoughts?
I have a question with regard to the sleep function declared in unistd.h
Assume we use a CFS scheduler.
We have a process that is ready to run(lets call this "READY" state),it gets picked to run,and now is running(so called "RUNNING" state).
During…