Transfering the process state to another process
Hi, We want to have a program which cannot be terminated by the user (even admin). I think the only way to do this is to write a watchdog process. So there will be a master and a slave process, the master will be the active process, and the slave keep on watching the master. I case if the master is terminated, the slave become master and initiates a new slave process. But we need to transfer (or share) the process state of "old master" with the "new master" (So that the new master can continue form where the old master has stopped). Is this possible with shared memory? Or is there is a better way? Thanks, Lloyd ______________________________________ Scanned and protected by Email scanner
On Thu, Nov 5, 2009 at 11:15 PM, Lloyd
Hi, We want to have a program which cannot be terminated by the user (even admin). I think the only way to do this is to write a watchdog process. So there will be a master and a slave process, the master will be the active process, and the slave keep on watching the master. I case if the master is terminated, the slave become master and initiates a new slave process. But we need to transfer (or share) the process state of "old master" with the "new master" (So that the new master can continue form where the old master has stopped). Is this possible with shared memory?
That might be hard, I can think of a number of ways to kill an entire tree of processes. Unless, say you are running on windows, you inject code into the running process system or winlogin.exe and have that act as your watchdog, or insert a low-level system hook to watch for all events passing through windows and block any that try to destroy your processes, but even all of that can be worked around. Security at the OS level, block access to the user would probably be the best bet (easier and safer on *nix then Windows). And of course, nothing helps if they have physical access to the machine. :)
Lloyd wrote:
Hi, We want to have a program which cannot be terminated by the user (even admin). I think the only way to do this is to write a watchdog process. So there will be a master and a slave process, the master will be the active process, and the slave keep on watching the master. I case if the master is terminated, the slave become master and initiates a new slave process. But we need to transfer (or share) the process state of "old master" with the "new master" (So that the new master can continue form where the old master has stopped). Is this possible with shared memory?
Or is there is a better way?
I imagine that any decent admin would tell you, politely: "Please don't try and create a process I cannot kill when it goes haywire, if you try I won't be running it in the first place." Fundamentally though you can try and create a process like that but you'll waste a lot of energy on something that you probably don't want to do anyway. Having said all that, ensuring that a process maintains some state so that processing can be continued by a newly created process in case it dies for some reason is a completely different matter. How you store the state will depend on what kind of state we're talking about, there's too many possiblities to try and guess at what you require. Details please. When it comes to gracefully restarting a process you will need to think about a few things. How will the watchdog tell when the current process is defunct? How quickly after becoming defunct must the process be restarted? What level of data "loss" is acceptable, and if we're talking about a server with clients, what happens to the work they've done so far? Again, this is a really huge landscape, and without knowing your requirements any advice is probably going to be of limited value. Regards, n
Trying to limit number of bytes transferred to at least 15 bytes before
async_read call back
I have got callbacks with sizes:
0,1,2,3,4 and 5 (so total indeed 15)
But I was expecting only single callback with size 15.
How I can fix the issue?
Thanks Vlad.
linux suse 2.6.16 boost 1.39 gcc 4.1.2
//boost asio stripped part.
BufferSize=1000;
class test{
vector<char> read_buffer_;
boost::asio::ip::tcp::socket socket_; //socket was inited correctly.
test() {
read_buffer_.reserve(BufferSize);
}
void handle_connect( const boost::system::error_code& err,
boost::asio::ip::tcp::resolver::iterator endpoint_iterator )
{
if (!err) {
boost::asio::async_read(socket_,boost::asio::buffer(read_buffer_,
BufferSize),
//requested at least 15 bytes!!
boost::asio::transfer_at_least(15),
boost::bind(&test::handle_read, this,
boost::asio::placeholders::error));
}
else {
cerr<
Unless I'm missing something it looks like you are passing zero-length vector to the buffer() function.
From asio docs this call is equivalent to:
mutable_buffers_1( data.size() ? &data[0] : 0, min(data.size() * sizeof(PodType), max_size_in_bytes)); ,where the data.size() = read_buffer_.size() i.e. zero for empty vector. You might try vector::resize(15) or just a size-taking constructor. Cheers, -- Nikolai
Trying to limit number of bytes transferred to at least 15 bytes before async_read call back I have got callbacks with sizes: 0,1,2,3,4 and 5 (so total indeed 15) But I was expecting only single callback with size 15.
How I can fix the issue?
Thanks Vlad.
linux suse 2.6.16 boost 1.39 gcc 4.1.2
//boost asio stripped part.
BufferSize=1000; class test{
vector<char> read_buffer_; boost::asio::ip::tcp::socket socket_; //socket was inited correctly.
test() { read_buffer_.reserve(BufferSize); }
void handle_connect( const boost::system::error_code& err, boost::asio::ip::tcp::resolver::iterator endpoint_iterator ) { if (!err) { boost::asio::async_read(socket_,boost::asio::buffer(read_buffer_, BufferSize), //requested at least 15 bytes!! boost::asio::transfer_at_least(15), boost::bind(&test::handle_read, this, boost::asio::placeholders::error)); } else { cerr<
void handle_read( const boost::system::error_code& err) { if (!err) { //+++++++++++++++++++++++++++ //expecting to get at least 15! //But have not get those. //+++++++++++++++++++++++++++ cerr<<"Got:"<
};
=============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ===============================================================================
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Have questions about using with tcp on linux. Can I send multiple messages to async_write without waiting for write completion callback? If yes, can I do it from more then one thread? Url with info would be handy. Thanks! =============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ===============================================================================
On Wed, Feb 10, 2010 at 5:19 PM, Sakharuk, Vladimir < vladimir.sakharuk@credit-suisse.com> wrote:
Have questions about using with tcp on linux. Can I send multiple messages to async_write without waiting for write completion callback? If yes, can I do it from more then one thread? Url with info would be handy.
Thanks!
=============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
===============================================================================
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
http://lists.boost.org/boost-users/2009/09/52017.php http://archives.free.net.ph/message/20090821.085221.7ccd0f8a.pt-BR.html http://www.jetbyte.com/portfolio-showarticle.asp?articleId=44&catId=1&subcatId=2 -- Matheus Araújo Aguiar Computer Scientist matheus.pit@gmail.com
Can I send multiple messages to async_write without waiting for write completion callback?
You mean, to the same socket? async_write() is a composite operation, it consists of multiple tcp::socket::asycn_write_some() calls. At least for this reason, your will be mixed-up.
If yes, can I do it from more then one thread?
No, tcp::socket is not thread-safe, you can't call its methods from multiple threads.
Hi, I am using boost:asio sync socket to upload file to server. At the end of upload, server send response back which can varying length and format. I need to read this response, considering that I haven't found a way to know how much data is available for reading, my call get blocked on some of the response. I Was wondering if there is a way to know one or more of the following. Is there condition I can pass to the read_until() call so that it read all the available response in one call? Is there a way to know that how much data remaining to be read? Is there a way that my call time out when there is no data? With three different server and response these call behave in following Manner Server1 : First call read all the data, 2nd call fail with error code EOF. Server2 :First call read all the data, 2nd call read some data, some time there are still more data to be read. Server2 :First call read all the data, 2nd call block. size_t size1 = boost::asio::read_until(*m_pSocket, response_, "\r\n", error); //process response, //Read again, size1 = boost::asio::read_until(*m_pSocket, response_, "\r\n\r\n", error); numByte = response_.in_avail(); //process response. Thanks, Akhilesh Kumar
I am using boost:asio sync socket to upload file to server. At the end of upload, server send response back which can varying length and format. I need to read this response, considering that I haven't found a way to know how much data is available for reading, my call get blocked on some of the response.
I Was wondering if there is a way to know one or more of the following.
Is there condition I can pass to the read_until() call so that it read all the available response in one call?
No. You can read "all the available response" using tcp::socket::read_some()/async_read_some(), but this would be the data available at time of the read operation - next moment some more data might arrive.
Is there a way to know that how much data remaining to be read?
tcp::socket::available() http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/basic_str...
Is there a way that my call time out when there is no data?
You can implement time-out using asynchronous read and asio::deadline_timer, just like in the following example: http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/example/timeouts/st...
Thanks Igor, This method " tcp::socket::available()" really solved most of my problem, this was the missing link for me after using WinInet for some time where I had convenience of using high level API I was really missing something while using BOOST::ASIO sync socket. This fills that gap. Thanks, Akhilesh Kumar -----Original Message----- From: boost-users-bounces@lists.boost.org [mailto:boost-users-bounces@lists.boost.org] On Behalf Of Igor R Sent: Sunday, February 14, 2010 7:49 AM To: boost-users@lists.boost.org Subject: Re: [Boost-users] boost::asio determining end of stream,
I am using boost:asio sync socket to upload file to server. At the end of upload, server send response back which can varying length and format. I need to read this response, considering that I haven't found a way to know how much data is available for reading, my call get blocked on some of the response.
I Was wondering if there is a way to know one or more of the following.
Is there condition I can pass to the read_until() call so that it read all the available response in one call?
No. You can read "all the available response" using tcp::socket::read_some()/async_read_some(), but this would be the data available at time of the read operation - next moment some more data might arrive.
Is there a way to know that how much data remaining to be read?
tcp::socket::available() http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/reference/basic_str...
Is there a way that my call time out when there is no data?
You can implement time-out using asynchronous read and asio::deadline_timer, just like in the following example: http://www.boost.org/doc/libs/1_42_0/doc/html/boost_asio/example/timeouts/st... _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
This method " tcp::socket::available()" really solved most of my problem
IUUC, available() cannot solve any fundamental problem, and it's bad idea to rely on it. You can use available() to perform some "speculative" blocking read, for exmaple, after your async_read_some() handler is called, but nobody can guarantee that you will not get some more data next moment, *after* you called available().
participants (8)
-
Igor R
-
Kumar, Akhilesh
-
Lloyd
-
Matheus Araújo Aguiar
-
Nigel Rantor
-
Nikolai N Fetissov
-
OvermindDL1
-
Sakharuk, Vladimir