精华内容
下载资源
问答
  • Linux系统调用 - close

    千次阅读 2018-10-23 23:08:05
    Close

    close系统调用的功能很直接,就是关闭一个已经打开的文件。函数原型:

    int close(int fd);
    

    fd就是之前用open()获得的一个文件描述符。

    在内核中,打开的文件会被维护一个引用计数,每次close()会把文件的引用计数减一,引用计数减少到0的文件才会从内核中释放资源。

    close()成功执行后会返回0,否则返回-1,同时失败原因会被记录在errno中。常见的错误原因有:
    EBADF:fd不是有效的文件描述符
    EINTR:close()被某个信号处理程序中断
    EIO:关闭文件时发生了IO错误

    调用close()而不检查返回值的代码非常常见,但是严格的说,这其实是个严重的编程错误,因为之前的write()操作也可能会导致close()的失败,如果就这样忽略close()的操作结果可能会导致数据的丢失,在NFS或者有限额的磁盘上尤其常见。

    一次成功的close()并不会总是保证所有的数据都会被刷新到磁盘上去,因为内核会延迟写。如果要在close()时需要保证所有的数据都已经保存到磁盘,要使用fsync()系统调用。

    另外,需要注意的是,close()的操作对象是文件描述符,它是一个能被重用的整数,所以,如果需要在多线程中操作一个文件,那在多线程中用这个文件描述符来应用该文件不是个好主意,如果一个线程中关闭了文件,然后重新打开的另一个文件重用了同一个整数文件描述符,那么在另外一个线程中就会操作到错误的文件。

    另外,如果要使用close()操作套接字,需要确保当前没有其他线程阻塞在该套接字的recv()上,因为该套接字关闭之后另外一个线程会永远收不到任何消息,从而永远阻塞在那里。这种情况下,应该先用shutdown()系统调用来结束所有的连接。

    ==================== 以下是广告 ====================

    更多系统详尽的Linux系统编程内容,欢迎订阅GitChat专栏 《攻克Linux系统编程》

    展开全文
  • The issue is that when I invoke window.close or self.close it doesn't close the window. Now there seems to be a belief that in Chrome you can't close by script any window that is not script ...

    The issue is that when I invoke window.close or self.close it doesn't close the window. Now there seems to be a belief that in Chrome you can't close by script any window that is not script created. That is patently false but regardless it is supposed to still do it, even if it requires to pop up an alert to confirm. These are not happening.

    So does anyone have real, functional and proven method of closing a window using something like javascript:window.close or javascript:self.close that actually does what is expected and something that happens just fine in every browser that is NOT Chrome based? Any suggestions would be greatly appreciated and I am looking for Javascript specific solution, nothing JQuery or third party implementation.


    Ordinary javascript cannot close windows willy-nilly. This is a security feature, introduced a while ago, to stop various malicious exploits and annoyances.

    From the latest working spec for window.close():

    The close() method on Window objects should, if all the following conditions are met, close the browsing context A:

    • The corresponding browsing context A is script-closable.
    • The browsing context of the incumbent script is familiar with the browsing context A.
    • The browsing context of the incumbent script is allowed to navigate the browsing context A.

    A browsing context is script-closable if it is an auxiliary browsing context that was created by a script(as opposed to by an action of the user), or if it is a browsing context whose session history contains only one Document.

    This means, with one small exception, javascript must not be allowed to close a window that was not opened by that same javascript.

    Chrome allows that exception -- which it doesn't apply to userscripts -- however Firefox does not. The Firefox implementation flat out states:

    This method is only allowed to be called for windows that were opened by a script using the window.open method.


    If you try to use window.close from a Greasemonkey / Tampermonkey / userscript you will get:
    Firefox: The error message, "Scripts may not close windows that were not opened by script."
    Chrome: just silently fails.



    The long-term solution:

    The best way to deal with this is to make a Chrome extension and/or Firefox add-on instead. These can reliably close the current window.

    However, since the security risks, posed by window.close, are much less for a Greasemonkey/Tampermonkey script; Greasemonkey and Tampermonkey could reasonably provide this functionality in their API (essentially packaging the extension work for you).
    Consider making a feature request.



    The hacky workarounds:

    Chrome is currently vulnerable to the "self redirection" exploit. So code like this will currently work in Tampermonkey scripts:

    open(location, '_self').close();
    

    This is buggy behavior, IMO, and is liable to be blocked by future releases of Chrome, so use this hack with that in mind.


    Firefox is secure against that exploit. So, the only javascript way is to cripple the security settings, one browser at a time.

    You can open up about:config and set
    allow_scripts_to_close_windows to true.

    If your script is for personal use, go ahead and do that. If you ask anyone else to turn that setting on, they would be smart, and justified, to decline with prejudice.

    There currently is no equivalent setting for Chrome.

    From my observation, this update fixed the issue on using window.close() to close the popup window. You will see this in the console when it fail, "Scripts may close only the windows that were opened by it.". That means The hacky workarounds (Brock Adams's answer) may not work in the latest release.

    So, in the previous Chrome released builds, the below code block may worked but not with this update.

    window.open('', '_self', '');
    window.close();
    

    For this update, you have to update your code accordingly to close the popup window. One of the solution is to grab the popup window id and use

    chrome.windows.remove(integer windowId, function callback)
    

    method to remove it. Chrome extension windows API can be found at chrome.windows.

    Actually my chrome extension MarkView was facing this issue and I had to update my code to make it work for this Chrome Update. By the way, MarkView is tool to read and write Awesome Markdown Files, it provides features including Content Outline, Sortable Tables and code block syntax highlight with line number.

    I also created this post, any comments are welcome.

    I use top.close() to close a tab. window.close() or other open...close didn't work for me.




    展开全文
  • 文章目录Channel shutdown: channel error; protocol method: #methodChannel shutdown: channel error;...channel.close>(rep 1、启动springboot 应用报错 Channel shutdown: channel error; pr...

    【RabbitMq】Channel shutdown: channel error; protocol method: #method<channel.close>(rep


    如果觉得本文对你有帮助,可以一键三连支持,谢谢

    1、启动springboot 应用报错

    Channel shutdown: channel error; protocol method: #method<channel.close>(rep

    2、原因

    当应用启动时,spring 会去检查注册的队列,跟服务器上的队列配置是否一致,如果不一致,则抛出这个错误

    比如你在项目中的配置是

        @Bean(DEAD_LETTER_PROD_CLOSE_ORDER)
        Queue a() {
            Map<String, Object> args = Maps.newHashMap();
            args.put("x-dead-letter-exchange", RabbitMqExchange.ExchangeCenter.DEAD_LETTER_EXCHANGE_CONSUME);
            args.put("x-dead-letter-routing-key", DEAD_LETTER_CONSUME_CLOSE_ORDER);
            args.put("x-message-ttl", 600 * 1000);
    
            return new Queue(DEAD_LETTER_PROD_CLOSE_ORDER, true, false, false, args);
        }
    

    但是服务器上的配置是

    x-message-ttl=1000
    

    则代码配置与现有队列配置不一致,抛出该错误

    3、解决

    方式一、修改项目配置与mq 保持一致

    修改项目配置与MQ一致则可以正常运行


    方式二、删除mq上现有队列
    删除mq 上现有队列,则springboot 自动向mq 服务器注册一个新的队列,也可以解决该问题

    本文地址 https://wretchant.blog.csdn.net/article/details/99976534
    博客地址 https://wretchant.blog.csdn.net/

    展开全文
  • resource failed to call close

    千次阅读 2021-05-26 11:27:30
    在运行Android项目时,日志中会出现A resource failed to call close告警信息: 2021-05-26 11:26:52.564 11386-11401/com.xxx.example W/System: A resource failed to call close. 这是由于文件输入和输出流在...

    在运行Android项目时,日志中会出现A resource failed to call close告警信息:

    2021-05-26 11:26:52.564 11386-11401/com.xxx.example W/System: A resource failed to call close. 
    

    这是由于文件输入和输出流在调用后没有及时close导致的,需要在调用后手动close掉输入输出流

    try {
    			FileInputStream fis = new FileInputStream(path);
    			FileChannel channel = fis.getChannel();
    			ByteBuffer byteBuffer = ByteBuffer.allocate((int) channel.size());
    			while ((channel.read(byteBuffer)) > 0) {
    				// do nothing
    			}
    			byte[] dataByte = byteBuffer.array();
    			channel.close(); //这里需要关闭channel,否则就会打印A resource failed to call close
    			return dataByte;
    		} catch (Throwable t) {
    		}
    
    展开全文
  • matlab中clc、clear、clear all、clf、closeclose all命令

    万次阅读 多人点赞 2019-05-19 11:57:17
    clc:清除命令窗口的内容 clear:清除工作空间的所有变量 clear all:清除工作空间的所有变量,函数,和MEX文件(MEX文件是一种可在matlab环境中调用的C语言(或fortran)衍生程序,mex...close all:关闭所有的Fi...
  • numpy.allclose与numpy.isclose介绍和区别

    千次阅读 2020-05-15 11:03:03
    numpy.allclose( ) numpy.allclose的官方文档https://docs.scipy.org/doc/numpy/reference/generated/numpy.allclose.html numpy.allclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source] 参数: a,b:...
  • 系统函数使用::来调用,所以close(fd)应该这样: ::close(fd); 其他函数亦然。 注意,别忘了加头文件: #include /*Unix 标准函数定义*/  #include /*文件控制定义*/
  • C++服务端CLOSE_WAIT问题排查

    千次阅读 2020-09-03 23:17:34
    CLOSE_WAIT问题排查问题描述问题排查总结 问题描述      服务端出现大量的处于CLOSE_WAIT状态的fd: 问题排查      TCP协议的状态转移这里就不再重述,出现...
  • np.allclose

    千次阅读 2019-10-21 17:29:28
    numpy的allclose方法,比较两个array是不是每一元素都相等,默认在1e-05的误差范围内 >>> help(np.allclose) Help on function allclose in module numpy.core.numeric: allclose(a, b, rtol=1e-05, ...
  • clc:清除命令窗口的内容,对工作环境中的全部变量无任何...close:关闭当前的Figure窗口 close all:关闭所有的Figure窗口 clear:清除工作空间的所有变量 clear all:清除工作空间的所有变量,函数,和MEX文件 ...
  • close函数

    千次阅读 2012-08-24 11:30:16
    close函数 所需头文件: #include 函数原型: int close(int fd) 返回值: 成功返回0,失败返回-1。 fd: 文件描述符
  • Connection: close

    千次阅读 2019-07-20 23:41:00
    在http1.1中request和reponse header中都有可能出现...在http1.1中,client和server都是默认对方支持长链接的, 如果client使用http1.1协议,但又不希望使用长链接,则需要在header中指明connection的值为close;如...
  • matlab中的close

    千次阅读 2014-04-11 21:54:40
    随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)、博主微信(guyun297890152)、QQ技术交流群(183198395)。 删除指定图 ...1、close:删除当前的图或者指定...
  • delphi filecloseclosefile的区别

    千次阅读 2014-04-14 15:04:05
    FileClose关闭用FileOpen或FileCreate方法打开的文件,需要提供文件句柄参数; CloseFile关闭用Reset、Rewrite或Append方法打开的文件,需要提供文件变量参数,这个参数由AssignFile方法获得。 代码如下所示:
  • 一直弹出出现closeChannel: close the connection to remote address[] result: true 解决: 首先查看阿里云服务器的安全组,是否打开了10911端口 然后查看conf/broker.conf 是否设置了brokerIP1=xxx.xxx.xxx.xxx...
  • ElasticSearch Open/Close Index

    千次阅读 2019-12-17 10:21:31
    ElasticSearch Open/Close Index 1、close index 2、open index 3、总结 针对部分索引,我们暂时不需要对其进行读写,可以临时关闭索引,以减少es服务器的开销 1、close index #为索引添加一条数据 put test/...
  • numpy.isclose

    千次阅读 2019-10-09 11:16:32
    numpy.isclose(a, b, rtol=1e-05, atol=1e-08, equal_nan=False)[source] Returns a boolean array where two arrays are element-wise equal within a tolerance. The tolerance values are positive, typically ...
  • close和SO_LINGER

    万次阅读 2017-08-26 14:12:20
    close函数的作用是关闭套接字,并终止TCP连接。unix网络编程这本书上是这样说的,我觉得这个解释有人会让人产生误解。close了某个socket,该socket就真的必须关闭吗?其实不是,close是将该套接字的引用计数减1,当...
  • selenium之 关闭窗口close与quit

    万次阅读 2016-08-26 16:36:51
    selenium关闭窗口有两个方法,close与quit,我们稍作研究便知道这两个方法的区别。1.看源码或API这是close()的说明: Closes the current window. 关闭当前窗口。 这是quit()的说明: Quits the driver and ...
  • close :关闭当前的Figure窗口  close all :关闭所有的Figure窗口  clear :清除工作空间的所有变量  clear all :清除工作空间的所有变量,函数,和MEX文件clc: clf :清除当前窗口图形,但不关闭窗口  ...
  • Matlab常用清除命令总结: clc命令:清空命令窗口中的内容。 clear命令:清空workspace(工作空间...close命令:关闭当前打开的figure图形界面。 close all:关闭所有的Figure窗口。 注:以上命令一般写在matl...
  • clc:清除命令窗口的内容 clear:清除工作空间的所有变量 clear all:清除工作空间的所有变量,函数,和MEX文件 clf:清除当前的Figure close:关闭当前的Figure窗口 close all:关闭所有的Figure窗口 ...
  • Golang亿点小细节之close()

    千次阅读 2021-03-19 10:30:36
    @Golang亿点小细节之close() 你所忽略的,往往才是Bug的起源 close() 前置知识 1.不能去close()一个已经close()的channle package main func main(){ ch := make(chan int) close(ch) close(ch) // output: //...
  • clc:清除命令窗口的内容,对工作环境中的全部变量无任何影响...close:关闭当前的Figure窗口 close all:关闭所有的Figure窗口 clear:清除工作空间的所有变量 clear all:清除工作空间的所有变量,函数,和MEX文件 ...
  • golang中的close函数

    千次阅读 2018-08-19 22:18:53
    close函数是用于关闭通道的。 官方解释(摘自close函数源代码注释): The close built-in function closes a channel, which must be either bidirectional or send-only. It should be executed only by the...
  • DISPOSE_ON_CLOSE:隐藏当前窗口,并释放窗体占有的其他资源。在窗口被关闭的时候会dispose这个窗口。 EXIT_ON_CLOSE:结束窗口所在的应用程序。在窗口被关闭的时候会退出JVM。 如果程序没有其他线程在运行,当...
  • 如果文件没有close会怎样

    千次阅读 2019-09-24 23:18:28
    文件如果没有close会怎样(文件编程要注意什么) 文件编程最后莫忘调用close函数关闭文件。如果不关闭文件,可能会导致文件临时数据丢失,造成文件写入失败。因为文件数据在关闭之前不保存在磁盘,而是保存在运行内存...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,635,927
精华内容 1,054,370
关键字:

close