C++ signals Linux


 
Thread Tools Search this Thread
Top Forums Programming C++ signals Linux
# 1  
Old 01-08-2012
C++ signals Linux

how can do this programs in c++

Program description:
Infinite loop in a program starts working with 2 seconds the screen (console) "I 'm trying" to write, but it automatically after 10 seconds, the screen "Close" will terminate the execution of typing.
c++ code
# 2  
Old 01-08-2012
Quote:
Originally Posted by ss54
how can do this programs in c++

Program description:
Infinite loop in a program starts working with 2 seconds the screen (console) "I 'm trying" to write, but it automatically after 10 seconds, the screen "Close" will terminate the execution of typing.
c++ code
I couldn't get your English, but I hope this is what you want, basically. This small program prints hello world on the screen after two seconds, for an infinite number of times.


Code:
 
#include <iostream>
using namespace std;
int main()
{
        while(1)
        {
                cout << "Hello, world!" << endl;
                sleep(2);
        }
return 0;
}


I hope it helps you
# 3  
Old 01-08-2012
i am sorry
i dont know english very well

programs after 10 seconds will be close automaticaly

my code:
Code:
#include <iostream>
#include <signal.h>
#include <unistd.h>
using namespace std;

void timeHandler(int a)
{
cout<<"I 'm trying";
alarm(2);
}
int main()
{
sinal(SIGALRM, timeHandler());
raise(SIGALARM);
while(1);        
return 0;
}


Last edited by fpmurphy; 01-09-2012 at 07:05 PM.. Reason: code tags please!
# 4  
Old 01-08-2012
Quote:
Originally Posted by ss54
i am sorry
i dont know english very well

programs after 10 seconds will be close automaticaly

my code:

#include <iostream>
#include <signal.h>
#include <unistd.h>
using namespace std;

void timeHandler(int a)
{
cout<<"I 'm trying";
alarm(2);
}
int main()
{
sinal(SIGALRM, timeHandler());
raise(SIGALARM);
while(1);
return 0;
}

Sorry mate, I am a novice myself, the only help that I could give you for the moment is, check the manual pages of all the functions, you will get all the details to solve your problem. Start by reading the manual page of the signal function, just type
Code:
 
man signal

Sorry once again, but don't worry someone would surely come for your help.

Good luck!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Help with Signals

Hi All, The problem statement is as below: Problem: A process (exe) is getting executed in background. The output of this process is getting logged in a file. After successfully running for some time the process gets terminated. In the log file following is present: ^M[7m Interrupt ^M[27m... (8 Replies)
Discussion started by: Praty.27
8 Replies

2. UNIX for Dummies Questions & Answers

perror with signals

I have following problem with this code.. First time trough the main loop..... perror gives ....blocked signal:success(all other times gives illlegal seek) Should every time trought the main loop be success?? And the perror otside of main loop...didn't change mask:success That line of code... (2 Replies)
Discussion started by: joker40
2 Replies

3. Programming

Signals and semaphores

I have problem with my application. Application is running on embedded Linux machine. It's basically multiprotocol gateway that connects two industrial Ethernet networks. We are experiencing some kind of application hang every 2 to 3 days. It seems like both threads are still running but... (12 Replies)
Discussion started by: _thomas
12 Replies

4. Programming

Using Signals

How can use signals in a C program If i want a child program to signal it's parent program that it(child) program has completed the task that it was assigned.:confused: (2 Replies)
Discussion started by: kapilv
2 Replies

5. UNIX for Dummies Questions & Answers

Signals...

(posted this in the scripting forum as well, but figured it should go here) So, what's going on is this: For our program, we had to create our own shell, and if the user pressed ctrl-c just at the cmdline, then this signal would be ignored, but if there is a foreground process running, let's... (0 Replies)
Discussion started by: blind melon
0 Replies

6. Programming

Threads Signals

Hi In my process there are few threads. Now, lets say all the threads are blocked for some reason or other.. now i read it somewhere that the kernel in this situation sends in some signal which can be caught. please let me know what signal is it and more details about that.. Thanks in... (1 Reply)
Discussion started by: uday_kumar_spl
1 Replies

7. UNIX for Advanced & Expert Users

Signals in Shell

Using Korn Shell on HP-UX 11.x Question about signals between two shells. First shell is the parent that kicks off the second shell. The first shell is going to ignore a standard set of signals, but I want the second shell to signal back to its parent if event X happens. Can I do something of... (5 Replies)
Discussion started by: google
5 Replies

8. UNIX for Dummies Questions & Answers

Kill with signals

Hi all, I am a beginning UNIX user and am looking for a list of possible signals (with explanation) that can be used with the command kill. Any input would be much appreciated. Thanks. Myriam (3 Replies)
Discussion started by: bz0rxf
3 Replies

9. Programming

Unix/Linux Newbie(ish) Question - IPC/Signals

:) Hello, i have been given the following code to help me learn how to use signals, it won't compile. The problem maybe because this was written for use in Unix and i am trying to compile in Linux. The error i get says that SIGPIPE and SIG_IGN are undeclared. I think that these are defined... (2 Replies)
Discussion started by: theultimatechuf
2 Replies

10. Programming

Signals In HP-UX

does the way of handling, interrupting signals in HP-UX same as that of solaris. If there is difference than what it is.?:confused: (1 Reply)
Discussion started by: kapilv
1 Replies
Login or Register to Ask a Question