top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

In linux, process running in background will be killed if we close the terminal?

+3 votes

Please understand the scenario :

I have an embedded system, on which i do telnet and then i starts i run an application using ./binary_name &.
Now if i close the terminal, and if i do telnet from new terminal then i can see above process is still running.

Now, To check this, i have written a sample program,


I just compiled it and i ran it on my linux PC using ./a.out &.
Then i just closed the terminal and from new terminal i checked using ps -elf command this process was killed.

My question is why different behavior for both process. i started both the process in background. Then why?

Any suggestion?

Thanks in advance

posted Sep 24, 2015 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
Is your local linux and server on which u telnet same :)
No, both are different by version,

Does it matter?
I have only found an answer,

AFAIK in both cases the process should be killed. In order to avoid this you have to issue a nohup like the following:

> nohup ./my_app &

This way your process will continue executing. Probably the telnet part is due to a BUG like the following:
Yes nohup is for freeing the process from terminal so that it keeps on running even after terminal is killed.
As you told different version hence bug may be the root cause.

Similar Questions
+4 votes

Lets assume I have a system with RAM of 1GB. and virtual memory is 500MB. That brings to 1.5GB i.e. 1500 MBytes.

I have read somewhere that when I process is created stack of 8MB is associated to that process. So, assuming that any of the process is not allocating any dynamic memory or anything, then does it mean that, Maximum number of process that i can create is 1500/8 and i.e. 187 Process.

Please clarify my understanding,

+4 votes

When a process is created using vfork() child process is created and starts running in the parent process address space, until exit() or exec() is called.

What happens to the parent process, if some one kills the child process before calling the exit()/exec()?

+4 votes

Code to write data in to file example.txt.. which is working fine

// basic file operations
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile; ("example.txt");
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  myfile << "Writing this to a file.\n";
  return 0;

File : filelimit.c below which takes input as the compiled binary of above code
In this code i am setting the file size limit of process to 10 bytes and the above code is trying to write more than 10 bytes. According to below code if a process is trying to write more than 10 bytes to file it should send the signal SIGXFSZ (see more about this here)

It is not sending here... Why??

#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

void handler(int sig)
    if(sig == SIGXFSZ)
        printf("Inside handler with correct signal\n");
        printf("Inside handler with wrong signal\n");

int main(int argc, char const *argv[])
    pid_t pid;
    pid = fork();

    if(pid == 0)
        signal(SIGXFSZ, handler);

        char command[256];
        scanf("%s", command);

        int ret;

        struct rlimit rl;
        rl.rlim_cur = 10;
        rl.rlim_max = 10;
        setrlimit (RLIMIT_FSIZE, &rl);

        char *envp[] = { NULL };
        char *argv[] = { command , NULL };
        ret = execve(command, argv, envp);

        printf("%d - %d\n", getpid(), pid);
        signal(SIGXFSZ, handler);
    return 0;
0 votes

There are two files.

    #include <stdio.h>
    void fun1(int i)
            int a;
            printf("Enter the number\n");

    int main()

/* INPUT  */    

What will be in file in OUTPUT file both cases.

./a.out < INPUT  > OUTPUT 

Case-2: Entered value is "18" from key board.

./a.out > output
+2 votes

Please share a sample program with detail code.

Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.