PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, August 18, 2022

[FIXED] How to kill/stop a running process in a terminal without losing its output?

 August 18, 2022     bash, c++, output, terminal     No comments   

Issue

I try to run a simple c++ code in a terminal and try to store its output in output.txt.

CODE-

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(1)
    {
        cin>>n;
        cout<<n;
    }
    return 0;
}

using a terminal commands:

g++ code.cpp
./a.out > output.txt

and input:

1 
2
3
4
5

but when I terminate the program by Ctrl+C, output.txt is empty. Thanks for the help in advance.


Solution

for me even it is working as you expect. I think maybe your task is not closed! so try two things: 1- try to close the terminal after crtl+C. after again check the content of output file 2- please give a good name instead of a.out(testfile.out) and after crtl+c try below command in shell:

sudo ps -aux | grep testfile

to see that your process either was killed or not



Answered By - SpongeBob
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing