精华内容
下载资源
问答
  • Watchdog

    2020-11-25 07:43:19
    <div><p>Watchdog not work! Atmega328p, Nokia 5110. If Watchdog is triggered then the microcontroller restarts and freeze (or enters the reboot cycle?!). It does not depend whether there is a ...
  • watchdog

    2020-12-08 19:05:29
    I did install manually using stretch and they say that the PI watchdog is not enabled by default. <p>There are lots of manuals around that describe how to set up the WD so that it triggers if a file...
  • WatchDog

    2013-07-10 09:42:13
    WatchDog1.先执行命令"insmod wdt.ko",2.再让WatchDog工作在reset模式“./app wdt_node”。此时一切正常. 其中文件wdt_node由命令“sudo mknode wdt_node c 52 0”创建。3.插入一个故障模块,使上一步中...

    1.先执行命令"insmod wdt.ko",

    2.再让WatchDog工作在reset模式“./app wdt_node”。此时一切正常.
        其中文件wdt_node由命令“sudo mknode wdt_node c 52 0”创建。
    3.插入一个故障模块,使上一步中的进程得不到调度。很快,系统重启。

    wdt.c代码如下:

    #include <linux/module.h>

    #include <linux/fs.h>
    #include <linux/cdev.h>
    #include <linux/ioport.h>
    #include <linux/interrupt.h>

    #include <asm/io.h>

    MODULE_LICENSE("GPL");
    MODULE_AUTHOR("zl");

    #define WDT_MAGIC    'Y'
    #define WDT_ON        _IOW(WDT_MAGIC, 0x00, int)
    #define WDT_OFF        _IOW(WDT_MAGIC, 0x01, int)
    #define WDT_MODE        _IOW(WDT_MAGIC, 0x02, int)
    #define WDT_FEED        _IOW(WDT_MAGIC, 0x03, int)

    struct watch_dog {
        unsigned long virt,phys;
        unsigned long wdtcon;
        unsigned long wdtdat;
        unsigned long wdtcnt;

        char name[1024];

        int reset_mode;
        int irq;

        void (*on)(struct watch_dog *);    
        void (*off)(struct watch_dog *);
        void (*mode)(struct watch_dog *, int);

        void (*feed)(struct watch_dog *);
        //----------------

        dev_t no;
        struct cdev dev;
    };

    void mywdt_on(struct watch_dog* mywdt)
    {
        iowrite32(ioread32(mywdt->wdtcon) | (<< 5), mywdt->wdtcon);
    }

    void mywdt_off(struct watch_dog* mywdt)
    {
        iowrite32(ioread32(mywdt->wdtcon) & ~(<< 5), mywdt->wdtcon);
    }

    void mywdt_mode(struct watch_dog* mywdt, int mymode)
    {
        unsigned long tmp;
        mywdt->reset_mode = mymode;

        tmp = ioread32(mywdt->wdtcon);
        if(mywdt->wdtcon)
        {
            iowrite32((tmp & ~(<< 2)) | 1, mywdt->wdtcon);            
        }
        else
        {
            iowrite32((tmp & ~1) | (<< 2), mywdt->wdtcon);
        }

    }
    void mywdt_feed(struct watch_dog* mywdt)
    {
        iowrite32(0x8000, mywdt->wdtcnt);
    }

    irqreturn_t mywdt_handle(int irq, struct watch_dog *mywdt)
    {
        printk("wdt timer....\n");    
        return IRQ_HANDLED;
    }

    int init_watch_dog(struct watch_dog *mywdt, const char *name )
    {
        int ret = 0;
        strcpy(mywdt->name, name);    
        mywdt->phys = 0x53000000;
        mywdt->irq = IRQ_S3C2440_WDT;
        mywdt->reset_mode = 0;

        ret = request_mem_region(mywdt->phys, SZ_4K, mywdt->name );
        if ((void *)ret == NULL) {
            ret = -EBUSY;
            goto err0;    
        }    
        
        ret = 0;
        mywdt->virt = ioremap(mywdt->phys, SZ_4K);
        if (mywdt->virt == NULL) {
            ret = -EBUSY;    
            goto err1;
        }

        mywdt->wdtcon = mywdt->virt + 0x00;
        mywdt->wdtdat = mywdt->virt + 0x04;
        mywdt->wdtcnt = mywdt->virt + 0x08;

        if (ret) {
            goto err2;    
        }

        mywdt->on = mywdt_on;
        mywdt->off = mywdt_off;
        mywdt->feed = mywdt_feed;
        mywdt->mode = mywdt_mode;

        iowrite32( 0x8004, mywdt->wdtcon);

        return ret;
    err2:
        iounmap(mywdt->virt);
    err1:
        release_mem_region(mywdt->phys, SZ_4K);    
    err0:
        return ret;
    }

    void destroy_watch_dog(struct watch_dog *mywdt)
    {
        iowrite32( 0x0, mywdt->wdtcon);
        iounmap(mywdt->virt);
        release_mem_region(mywdt->phys, SZ_4K);
        free_irq(mywdt->irq, mywdt);
    }

    //----------------------------------------

    int mywdt_ioctl(struct inode *no, struct file *fp, unsigned long cmd, unsigned long arg)
    {
        int ret = 0;
        struct watch_dog *mywdt = container_of(no->i_cdev, struct watch_dog, dev);

        switch(cmd) {
            case WDT_ON:
            mywdt->on(mywdt);
            break;

            case WDT_OFF:
            mywdt->off(mywdt);
            break;

            case WDT_MODE:
            mywdt->mode(mywdt, arg);
            break;

            case WDT_FEED:
            mywdt->feed(mywdt);
            break;

            default:
            ret = -EINVAL;
            break;
        }

        return ret;
    }

    struct watch_dog s3c2440_wdt;
    struct file_operations s3c2440_wdt_ops = {
        .ioctl = mywdt_ioctl,
    };
    int test_init(void)
    {
        int ret = 0;
        
        ret = init_watch_dog(&s3c2440_wdt, "s3c2440 watch dog");
        if (ret) {
            goto err0;
        }
        
        s3c2440_wdt.no = MKDEV(52, 0);
        ret = register_chrdev_region(s3c2440_wdt.no, 1, s3c2440_wdt.name);
        if (ret) {
            goto err1;    
        }

        cdev_init(&s3c2440_wdt.dev, &s3c2440_wdt_ops);
        cdev_add(&s3c2440_wdt.dev, s3c2440_wdt.no, 1);        

        return ret;
    err1:
        destroy_watch_dog(&s3c2440_wdt);

    err0:
        return ret;
    }

    void test_exit(void)
    {
        destroy_watch_dog(&s3c2440_wdt);    
        cdev_del(&s3c2440_wdt.dev);
        unregister_chrdev_region(s3c2440_wdt.no, 1);
    }

    module_init(test_init);
    module_exit(test_exit);


    app.c文件代码创建一个守护进程,使WatchDog工作在reset模式。每0.1秒执行一次喂狗,内容如下:


    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <fcntl.h>
    #include "wdt.h"

    int main(int argc, char **argv)
    {
        int fd;
        unsigned cmd;
        if (argc < 2) {
            printf("Usage: %s <file> \n", argv[0]);
            return 0;
        }

        fd = open(argv[1], O_RDWR);

        chdir("/");
        close(0);close(1);close(2);    

        if (fork()) {
            return 0;    
        }

        ioctl(fd, WDT_MODE, 1);
        ioctl(fd, WDT_ON);

        while(1) {
            ioctl(fd, WDT_FEED);    
            usleep(100 * 1000);
        }

        close(fd);
        return 0;
    }


    故障模块文件代码bad_module.c禁止内核抢占,然后一个死循环把系统卡死,这样上面的"./app wdt_node"命令启动的守护进程就得不到调度。代码如下:


    #include <linux/module.h>
    
    MODULE_LICENSE("GPL");
    MODULE_AUTHOR("zl");
    
    int test_init(void)
    {
        preempt_disable();
        while(1);
    
        return 0;
    }
    
    void test_exit(void)
    {
    }
    
    module_init(test_init);
    module_exit(test_exit);
    
    

    展开全文
  • python watchdog_watchdog

    2020-12-04 19:35:00
    Watchdog Python API and shell utilities to monitor file system events.Works on Python 2.7 and 3.4+. If you want to use an old version of Python, youshould stick with watchdog < 0.10.0.Example API U...

    Watchdog

    Python API and shell utilities to monitor file system events.

    Works on Python 2.7 and 3.4+. If you want to use an old version of Python, you

    should stick with watchdog < 0.10.0.

    Example API Usage

    A simple program that uses watchdog to monitor directories specified as

    command-line arguments and logs events generated:

    import sys

    import time

    import logging

    from watchdog.observers import Observer

    from watchdog.events import LoggingEventHandler

    if __name__ == "__main__":

    logging.basicConfig(level=logging.INFO,

    format='%(asctime)s - %(message)s',

    datefmt='%Y-%m-%d %H:%M:%S')

    path = sys.argv[1] if len(sys.argv) > 1 else '.'

    event_handler = LoggingEventHandler()

    observer = Observer()

    observer.schedule(event_handler, path, recursive=True)

    observer.start()

    try:

    while True:

    time.sleep(1)

    except KeyboardInterrupt:

    observer.stop()

    observer.join()

    Shell Utilities

    Watchdog comes with an

    optional

    utility script called

    watchmedo

    . Please

    type

    watchmedo --help

    at the shell prompt to know more about this tool.

    Here is how you can log the current directory recursively for events related

    only to

    *.py

    and

    *.txt

    files while ignoring all directory events:

    watchmedo log \

    --patterns="*.py;*.txt" \

    --ignore-directories \

    --recursive \

    .

    You can use the

    shell-command

    subcommand to execute shell commands in

    response to events:

    watchmedo shell-command \

    --patterns="*.py;*.txt" \

    --recursive \

    --command='echo "${watch_src_path}"' \

    .

    Please see the help information for these commands by typing:

    watchmedo [command] --help

    About

    watchmedo

    Tricks

    watchmedo

    can read

    tricks.yaml

    files and execute tricks within them in

    response to file system events. Tricks are actually event handlers that

    subclass

    watchdog.tricks.Trick

    and are written by plugin authors. Trick

    classes are augmented with a few additional features that regular event

    handlers don't need.

    An example

    tricks.yaml

    file:

    tricks:

    - watchdog.tricks.LoggerTrick:

    patterns: ["*.py", "*.js"]

    - watchmedo_webtricks.GoogleClosureTrick:

    patterns: ['*.js']

    hash_names: true

    mappings_format: json # json|yaml|python

    mappings_module: app/javascript_mappings

    suffix: .min.js

    compilation_level: advanced # simple|advanced

    source_directory: app/static/js/

    destination_directory: app/public/js/

    files:

    index-page:

    - app/static/js/vendor/jquery*.js

    - app/static/js/base.js

    - app/static/js/index-page.js

    about-page:

    - app/static/js/vendor/jquery*.js

    - app/static/js/base.js

    - app/static/js/about-page/**/*.js

    The directory containing the

    tricks.yaml

    file will be monitored. Each trick

    class is initialized with its corresponding keys in the

    tricks.yaml

    file as

    arguments and events are fed to an instance of this class as they arrive.

    Tricks will be included in the 0.5.0 release. I need community input about

    them. Please file enhancement requests at the

    issue

    tracker

    .

    Installation

    Install from PyPI using

    pip

    :

    $ python -m pip install watchdog

    # or to install the watchmedo utility:

    $ python -m pip install watchdog[watchmedo]

    Install from source:

    $ python -m pip install -e .

    # or to install the watchmedo utility:

    $ python -m pip install -e .[watchmedo]

    Installation Caveats

    The

    watchmedo

    script depends on

    PyYAML

    which links

    with

    LibYAML

    , which brings a performance

    boost to the PyYAML parser. However, installing

    LibYAML

    is optional but recommended. On Mac

    OS X, you can use

    homebrew

    to install

    LibYAML:

    $ brew install libyaml

    On Linux, use your favorite package manager to install LibYAML. Here's how you

    do it on Ubuntu:

    $ sudo aptitude install libyaml-dev

    On Windows, please install

    PyYAML

    using the binaries

    they provide.

    Documentation

    You can browse the latest release

    documentation

    online.

    Contribute

    Fork the

    repository

    on GitHub and

    send a pull request, or file an issue ticket at the

    issue

    tracker

    . For general help and

    questions use the official

    mailing

    list

    or ask on

    stackoverflow

    with tag python-watchdog.

    Create and activate your virtual environment, then:

    python -m pip install pytest pytest-cov

    python -m pip install -e .[watchmedo]

    python -m pytest tests

    If you are making a substantial change, add an entry to the "Unreleased"

    section of the

    changelog

    .

    Supported Platforms

    Linux 2.6 (inotify)

    Mac OS X (FSEvents, kqueue)

    FreeBSD/BSD (kqueue)

    Windows (ReadDirectoryChangesW with I/O completion ports; ReadDirectoryChangesW worker threads)

    OS-independent (polling the disk for directory snapshots and comparing them periodically; slow and not recommended)

    Note that when using watchdog with kqueue, you need the number of file

    descriptors allowed to be opened by programs running on your system to be

    increased to more than the number of files that you will be monitoring. The

    easiest way to do that is to edit your

    ~/.profile

    file and add a line

    similar to:

    ulimit -n 1024

    This is an inherent problem with kqueue because it uses file descriptors to

    monitor files. That plus the enormous amount of bookkeeping that watchdog

    needs to do in order to monitor file descriptors just makes this a painful way

    to monitor files and directories. In essence, kqueue is not a very scalable

    way to monitor a deeply nested directory of files and directories with a large

    number of files.

    About using watchdog with editors like Vim

    Vim does not modify files unless directed to do so. It creates backup files

    and then swaps them in to replace the files you are editing on the disk. This

    means that if you use Vim to edit your files, the on-modified events for those

    files will not be triggered by watchdog. You may need to configure Vim

    appropriately to disable this feature.

    Dependencies

    Python 2.7, 3.4 or above.

    XCode

    (only on Mac OS X)

    PyYAML

    (only for

    watchmedo

    script)

    argh

    (only for

    watchmedo

    script)

    Licensing

    Watchdog is licensed under the terms of the

    Apache License, version

    2.0

    .

    Copyright 2012 Google, Inc.

    Project

    source code

    is available at

    Github. Please report bugs and file enhancement requests at the

    issue

    tracker

    .

    Why Watchdog?

    Too many people tried to do the same thing and none did what I needed Python

    to do:

    展开全文
  • Linux watchdog

    2020-10-16 14:10:07
    使用 watchdog 构建高可用性的 Linux 系统及应用 https://www.ibm.com/developerworks/cn/linux/l-cn-watchdog/index.html watchdog(8):软件看门狗守护进程 - Linux手册页 https://linux.die.net/man/8/watchdog ...

    使用 watchdog 构建高可用性的 Linux 系统及应用
    https://www.ibm.com/developerworks/cn/linux/l-cn-watchdog/index.html

    watchdog(8):软件看门狗守护进程 - Linux手册页
    https://linux.die.net/man/8/watchdog

    watchdog_百度百科
    https://baike.baidu.com/item/Watchdog/5403686

    linux watchdog看门狗编程 - 简书
    https://www.jianshu.com/p/b0528ec1d01d

    linux watchdog demo hacking - zengjf - 博客园
    http://www.cnblogs.com/zengjfgit/p/5328356.html

    watchdog首页、文档和下载 - Linux看门狗 - 开源中国
    https://www.oschina.net/p/watchdog

    Watchdog (Linux)

    Watchdog

    展开全文
  • WatchDog.zip

    2021-04-01 09:50:42
    WatchDog.zip
  • Watchdog refactoring

    2021-01-09 12:01:00
    <pre><code>Watchdog refactoring to multithreaded thread. -Added API to register muliple threads to watchdog drivers -Watchdog timeout reconfigures everytime whenever new register thread with longer ...
  • <div><p>Add watchdog driver for the RT1050/60 <p>Signed-off-by: Crist Xu <p>Fixes #27122</p><p>该提问来源于开源项目:zephyrproject-rtos/zephyr</p></div>
  • Sw watchdog

    2021-01-07 12:27:57
    - Add SW watchdog functionality, triggered by lack of heartbeat from: main thread, main worker thread, and any thread registered by MainWorker::HeartbeatUpdate, including webservers - Remove unsafe ...
  • Of watchdog

    2021-01-02 10:51:30
    <div><p>An adaptation of <code>of-watchdog</code>. As per openfaas in future all of the templates going to use the <code>of-watchdog</code></p> <p>This PR migrates from <code>go</code> template ...
  • <div><p>For using watchdog in user context, mapping the imxrt watchdog functions to watchdog drivers.</p><p>该提问来源于开源项目:Samsung/TizenRT</p></div>
  • /usr/bin/python# -*- coding:UTF-8 -*-import timefrom watchdog.observers import Observerfrom watchdog.events import RegexMatchingEventHandlerclass MyHandler(RegexMatchingEventHandler):def __ini...

    监视文件变更

    #!/usr/bin/python

    # -*- coding:UTF-8 -*-

    import time

    from watchdog.observers import Observer

    from watchdog.events import RegexMatchingEventHandler

    class MyHandler(RegexMatchingEventHandler):

    def __init__(self, regex_list=[r".*"]):

    super(MyHandler, self).__init__(regex_list)

    def on_created(self, event):

    if event.is_directory:

    pass

    else:

    print(event.event_type, event.src_path)

    def on_deleted(self, event):

    if event.is_directory:

    pass

    else:

    print(event.event_type, event.src_path)

    def on_modified(self, event):

    if event.is_directory:

    pass

    else:

    print(event.event_type, event.src_path)

    def on_moved(self, event):

    print("move", event.src_path, event.dest_path)

    if __name__ == "__main__":

    reges = [r".*\.c", r".*\.h", r".*\.cpp"]

    event_handler = MyHandler(reges)

    observer = Observer()

    observer.schedule(event_handler, ".", recursive=True)

    observer.start()

    try:

    print("start my watch")

    while True:

    time.sleep(100)

    except KeyboardInterrupt:

    observer.stop()

    observer.join()

    读取配置文件

    # -*- coding: utf-8

    from configparser import ConfigParser

    def get_config(section_name="env", conf_file="ssh-config.ini"):

    '''

    :param section_name:

    :param conf_file:

    :return dictornary:

    eg.

    [env]

    user = root

    password = root123

    return {"user":"root", "password":"root123"}

    '''

    config = ConfigParser()

    config.read_file(open(conf_file))

    return dict(config.items(section_name))

    for k, v in get_config().items():

    print(k, ":", v)

    展开全文

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 6,577
精华内容 2,630
关键字:

watchdog