Why, Background Process
Just an thought about Background Process.
Can't we use background process as remainders...
Consider the following examples... Suppose if we want to print some message on the console after some interval of time, then in such condition we can use background process as remainder.The below chunk of code meets the above requirement.
#include
void main( int argc char *argv[] )
{
int time_sec = 0;
time_sec = atoi ( argv [ 2 ] );
sleep ( time_sec );
printf ( " %s\n ", argv [ 1 ] );
}
Run:./a.out " Hello World " 4Prints Hello World on the console after 4 seconds.
Consider one more useful example, suppose if you would like to copy a large content of data from one file to another. Surely this would take some time to complete the task. Its a very bad practice if we block our main process until the copying process complete. Instead we can create a separate background process and get the task done through that process. This will ensures the smooth flow.
Snippet of code to illustrate copying process...
#include
void main ( int argc, char *argv [] )
{
FILE *readFilePtr, *writeFilePtr;
char c;
readFilePtr = fopen ( " inputFile " , r );
writeFilePtr = fopen ( " outputFile " , w );
while ( c = fgetc ( readFilePtr ) != EOF )fputc ( c, writeFilePtr );
sys_beep( 2 );
}
One more situation wherein which this is useful is, when the system administrators wants to know who are all the users currently logged in to the system at regular interval of time.
Unix command to achieve the above task is: who wc -l
if somebody knows any other situation wherein which these background process are most useful, please share with us...
Yours,
Satish
Can't we use background process as remainders...
Consider the following examples... Suppose if we want to print some message on the console after some interval of time, then in such condition we can use background process as remainder.The below chunk of code meets the above requirement.
#include
void main( int argc char *argv[] )
{
int time_sec = 0;
time_sec = atoi ( argv [ 2 ] );
sleep ( time_sec );
printf ( " %s\n ", argv [ 1 ] );
}
Run:./a.out " Hello World " 4Prints Hello World on the console after 4 seconds.
Consider one more useful example, suppose if you would like to copy a large content of data from one file to another. Surely this would take some time to complete the task. Its a very bad practice if we block our main process until the copying process complete. Instead we can create a separate background process and get the task done through that process. This will ensures the smooth flow.
Snippet of code to illustrate copying process...
#include
void main ( int argc, char *argv [] )
{
FILE *readFilePtr, *writeFilePtr;
char c;
readFilePtr = fopen ( " inputFile " , r );
writeFilePtr = fopen ( " outputFile " , w );
while ( c = fgetc ( readFilePtr ) != EOF )fputc ( c, writeFilePtr );
sys_beep( 2 );
}
One more situation wherein which this is useful is, when the system administrators wants to know who are all the users currently logged in to the system at regular interval of time.
Unix command to achieve the above task is: who wc -l
if somebody knows any other situation wherein which these background process are most useful, please share with us...
Yours,
Satish
0 Comments:
Post a Comment
<< Home