lseek(fd - file descriptor of the open file , index -from what position we should
write,SEEK_SET /SEEK_CUR / SEEK_END
PROCESS:
program in execution ;
------------------------------
if two instances of a program can share the same virtual memory address at the same
time even if te data is different. --> run the program in two different variables
passing from command line in two terminals at same time
echo 2 | sudo tee /proc/sys/kernel/randomize_va_space
---------------------
process states
interrupt
admit <-- exit
start --> ready --> running --> terminated
| scheduler dispatch|
wait ----------------------
----------------------------------------------------------------------
process system calls:
int fork(void)
int execv(char *progName, char *argv[])
void exit(int returnCode)
int wait(int *returnCode)
1) int fork(void)
description: ceate the child process --> return the intiger process id of the new
process
child process will have id 0;
------------------
int execv(char *progName, char *argv[])
description: load the program in process address space ; returns -1 if failed
the program is laded in the calling process address space and the old program is
over and no longer available
---------------
void exit(int returnCode)
description: terminate process; causes a normal process terminatem, its basically
just a process to exit, and it return the code which is the return code to parent
process
---------------------
int wait(int *returnCode)
description: await process completion ; returns the process ID of process that
exited
it is basically a calling process to wait until any process created by the call and
process exits
--------------------------
THREADS: pthreads
baisc unit of CPU utilization ; shares resources with other threads in the same
process
there is a lot of overhead and it takes a lot of cpu clock cycles to crete and
destroy threads within process
10 threads in 1 process or 100 threads in 1 process --> 10 threads because there is
a lot of overhead in creating and destroying 100 threads
----------------------------
int pthread_create(..)
1 description: create a new thread --> returns 0 if success
pthread_t *myThread;
pthread_create(myThread..);
--------------
int pthread_join(...)
description: wait for thread to finish
return 0 if success
a very common way to wait for threads to finish is if you have a program that
creates 10 threads and you want towait for all the threads to complete executing
before you move on with your main code, use below for loop
for(int i=0; i< NUM_THREADS; i++)
{
pthread_join(thread[i],NULL);
}
-------------------
void pthread_exit()
description: terminates running thread ; returns : none