18/08/2020
Learn Coding & problem solving techniques. WhatsApp 9811631557 for more info.
This page is all about programming in C & C++ updates and features.
18/08/2020
Learn Coding & problem solving techniques. WhatsApp 9811631557 for more info.
09/05/2020
Guys subscribe this channel for C and C++ Free online tutorials.
SRC LEARNING SRI RAAM COMPUTER EDUCATION, started in JAN 2004 , is a training centre imparting quality education up holding its motto “Education goes beyond business”. Th...
Zombie and Orphan Processes in C
Prerequisite: fork() in C
Zombie Process:
A process which has finished the ex*****on but still has entry in the process table to report to its parent process is known as a zombie process. A child process always first becomes a zombie before being removed from the process table. The parent process reads the exit status of the child process which reaps off the child process entry from the process table.
In the following code, the child finishes its ex*****on using exit() system call while the parent sleeps for 50 seconds, hence doesn’t call wait() and the child process’s entry still exists in the process table.
// A C program to demonstrate Zombie Process.
// Child becomes Zombie as parent is sleeping
// when child process exits.
int main()
{
// Fork returns process id
// in parent process
pid_t child_pid = fork();
// Parent process
if (child_pid > 0)
sleep(50);
// Child process
else
exit(0);
return 0;
}
Note that the above code may not work with online compiler as fork() is disabled.
Orphan Process:
A process whose parent process no more exists i.e. either finished or terminated without waiting for its child process to terminate is called an orphan process.
In the following code, parent finishes ex*****on and exits while the child process is still executing and is called an orphan process now.
However, the orphan process is soon adopted by init process, once its parent process dies.
// A C program to demonstrate Orphan Process.
// Parent process finishes ex*****on while the
// child process is running. The child process
// becomes orphan.
int main()
{
// Create a child process
int pid = fork();
if (pid > 0)
printf("in parent process");
// Note that pid is 0 in child process
// and negative if fork() fails
else if (pid == 0)
{
sleep(30);
printf("in child
process");
}
return 0;
}
31/03/2017
Single linked list functional architecture
Following are the differences between Structures in C and Structures in C++ :
1. Structures in C cannot have Direct functions/methods inside a structure definition[But it still can have methods in the form of function pointers]. While structures in C++ can have functions/methods inside a structure definition.
2. In C, an object(variable) of a structure is created using the keyword struct(otherwise syntax error). For example struct student sid; Whereas in C++ the struct keyword can be omitted while creating structure variables(objects). For example: student sid;
3. C structures does not permit Data hiding concept whereas C++ structures allow Data hiding.